While doing project , I found a script that is bounced over my head. Can you help me to understand this script . Please explain this script step by step.


if ! [ -f /usr/local/bin/XXX -a -f /usr/local/bin/YYY -a -f /usr/local/bin/ZZZ ]
    if [ "`uname`" = "Linux" ]
        UUDECODE="uudecode -o /dev/stdout"
        UUDECODE="uudecode -p"
    cat $0 | awk 'printme == "1" {print} /^DATA BEGINS HERE/ {printme = "1"}' | ${UUDECODE} | (cd /usr/local/bin ; sudo tar xzf - --unlink)
    sudo chmod AAAA /usr/local/bin/XXX /usr/local/bin/YYY

My understanding so far

  1. This script checks if XXX , YYY , ZZZ is present in /usr/local/bin , is present or not.
  2. If not then it enters in the body of if.
  3. If current OS is Linux, then it do
  4. But after that I didn't understand.

Strange after running this script these three executables are in /usr/local/bin. Explain below script line by line please.

One thing that I mention that, at the end of script, there is some unreadable data is there, starting from "DATA BEGINS HERE". Is this script copies this data to /usr/local/bin ?

1 Answer 1


If it is Linux, it sets UUDECODE to one form of calling the command uudecode, if not, another one. It isn't standard, so how to call it varies. Not very smart, if you ask me.

The line starting cat $0 does the real work. $0 is the name of the running process, i.e., of the current script. Again, will mostly work but can be fooled.

The contents of the script are piped to the awk script, which copies all the text after DATA BEGINS HERE to its output, which is piped to uudecode (the command set up before). uudecode takes text and makes a binary of it (the pair uuencode/uudecode where used to ship binaries around as text before HTTP and others became popular), the result is piped to the command in '()', which first changes into /usr/local/bin and then unpacks the input with tar there. The --unlink first deletes any existing file.

Where does this come from?!

  • This is related to my college project.
    – devsda
    Commented Mar 21, 2013 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .