Bash Special Parameters

这些古怪的符号,其实都是有含义有规律的。弄懂它们一点都不难,只需要写点代码,运行一下就知道了。perl 的特殊变量更多,perldoc perlvar.

#/bin/bash
 
# http://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
 
# run it like 
# ./spec_para.sh 1 2 3
 
# Parameters
echo $_ # absolute pathname
echo $0 # ./spec_para.sh
echo $1 # 1
echo $2 # 2
echo $3 # 3
 
# $* and $@ is differents
echo $@ # 1 2 3 ("$1" "$2" "$3")
echo $* # 1 2 3 ("$1c$2c$3")
# c is the first character of the value of the IFS variable. If IFS is
# unset, the parameters are separated by spaces. If IFS is null, the
# parameters are joined without intervening separators. 
 
echo $# # 3 ( number of positional parameters in decimal )
 
echo $? # exit status of the most recently executed foreground pipeline 
echo $$ # process ID of the shell
echo $! # process ID of the most recently executed background command
 
echo $- # current option flags
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">