#1.1. create the script file named /tmp/tst
cat>/tmp/tst <<"EOD"
echo "\$0 returns program name: $0"
echo "\$1 returns the 1st argument: $1"
echo "\$* returns the argument list: $*"
echo "\$@ returns the argument list: $@"
echo "\$$ returns the shell PID: $$"
echo "\$_ returns the lastest command: $_"
echo "\${#@} returns the argument number:${#@}"
echo "\${!#} returns the last argument: ${!#}"
echo "\$# returns the argument num: $#"
echo "\$- returns the shell options list:$-"
echo "\$OPTARG returns the next element of argv:$OPTARG"
echo "\$OPTIND returns the next index of argv: $OPTIND"
EOD
#2.2. invoke the script file to test special variables
bash /tmp/tst a{1..3}
#3.3. create a function named func1
func1(){
echo "\$0 returns program name: $0"
echo "\$1 returns the 1st argument: $1"
echo "\$* returns the argument list: $*"
echo "\$@ returns the argument list: $@"
echo "\$$ returns the shell PID: $$"
echo "\$_ returns the lastest command: $_"
echo "\${#@} returns the argument number:${#@}"
echo "\${!#} returns the last argument: ${!#}"
echo "\$# returns the argument num: $#"
return 0 #zero is right,function will be called as subshell
}
#4.3. invoke the function to test the special variables
func1 p{1..4} #or func p1 p2 p3 p4
echo "the return value is $?"
-------output----------
#1.1. create the script file named /tmp/tst
#2.2. invoke the script file to test special variables
$0 returns program name: /tmp/tst
$1 returns the 1st argument: a1
$* returns the argument list: a1 a2 a3
$@ returns the argument list: a1 a2 a3
$$ returns the shell PID: 18805
$_ returns the lastest command: $$ returns the shell PID: 18805
${#@} returns the argument number:3
${!#} returns the last argument: a3
$# returns the argument num: 3
$- returns the shell options list:hB
$OPTARG returns the next element of argv:
$OPTIND returns the next index of argv: 1
#3.3. create a function named func1
#4.3. invoke the function to test the special variables
$0 returns program name: bash
$1 returns the 1st argument: p1
$* returns the argument list: p1 p2 p3 p4
$@ returns the argument list: p1 p2 p3 p4
$$ returns the shell PID: 18803
$_ returns the lastest command: $$ returns the shell PID: 18803
${#@} returns the argument number:4
${!#} returns the last argument: p4
$# returns the argument num: 4
the return value is 0
|
#1.1. create the script file named /tmp/tst
cat>/tmp/tst <<'EOF'
use feature ":5.10";
say "the script name :\$0 -->$0";
say "the argument list:\@ARGV -->@ARGV";
say "the argument 1st :\$ARGV[0] -->$ARGV[0]";
say "the argument num :\scalar(\@ARGV) -->".scalar(@ARGV);
say "the argument num :0+\@ARGV -->".(0+@ARGV);
say "the argument num :1+\$#ARGV -->".(1+$#ARGV);
EOF
#2.2. invoke the script file to test special variables
perl /tmp/tst arg1 arg2 arg3
-------output----------
the script name :$0 -->/tmp/tst
the argument list:@ARGV -->arg1 arg2 arg3
the argument 1st :$ARGV[0] -->arg1
the argument num :scalar(@ARGV) -->3
the argument num :0+@ARGV -->3
the argument num :1+$#ARGV -->3
|
#1.1. create the script file named /tmp/tst
cat >/tmp/tst<<'EOF'
import sys
import os
print "the argument array: sys.argv -->", sys.argv
print "the script name: sys.argv[0] -->", sys.argv[0]
print "the script name: __file__ -->", __file__
print "the array of path: sys.path -->", sys.path[0]
print "the script path: sys.path[0] -->", sys.path[0]
EOF
#2.2. invoke the script file to test special variables
python /tmp/tst arg1 arg2 arg3
-------output----------
the argument array: sys.argv --> ['/tmp/tst', 'arg1', 'arg2', 'arg3']
the script name: sys.argv[0] --> /tmp/tst
the script name: __file__ --> /tmp/tst
the array of path: sys.path --> /tmp
the script path: sys.path[0] --> /tmp
|