2012年6月29日星期五

three special linux shell variables


Here are some other special variables you will find useful in script writing:
$# The number of arguments
$* The entire argument string
$? The return code from the last command issued

So let's try some examples working with arguments and other special variables. Create an executable script called testvars containing these lines:

echo "My name is $0"
echo "First arg is: $1"
echo "Second arg is: $2"
echo "I got a total of $# arguments."
echo "The full argument string was: $*"

Now if you run this script, here's what you'll see:

$ ./testvars birds have lips
My name is testvars
First arg is: birds
Second arg is: have
I got a total of 3 arguments.
The full argument string was: birds have lips

http://lowfatlinux.com/linux-script-variables.html#SHELL

没有评论:

发表评论