UNIX shell script question
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.)
i don’t know of any way other than that.
according to this, it’s:
$* 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.
|
i don’t know of any way other than that.
according to this, it’s: $* 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. |
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).
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.