UNIX shell script question

Discussion in 'OT Technology' started by trouphaz, Aug 7, 2008.

  1. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    I'm writing a ksh script and I want to echo the command that was run to call this script. So, if someone ran "/path/to/script -f blah blah apple -x file" I want the script to echo "/path/to/script -f blah blah apple -x file" to a log file. Is there a better way than typing this?
    echo "$0 $@"

    or

    echo "$0 $*"

    (I'm trying to remember what the difference between $@ and $*, but right now they are behaving the same.)
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,448
    Likes Received:
    12
    i don't know of any way other than that.

    according to this, it's:

    http://www.dartmouth.edu/~rc/classes/ksh/arguments.html

    $* contains all of the arguments in a single string, with one space separating them.

    $@ similar to $*, but if used in quotes, it effectively quotes each argument and keeps them separate. If any argument contains whitespace, the distinction is important.
     
  3. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0

    nice, thanks. yeah, i generally keep my arguments in my shell scripts to single words and not really strings, so the distinction wasn't appearing to me.

    i guess i'll stick with $0 $@ (just in case, i'm trying to capture the command as it is run for debugging).
     

Share This Page