1、
http://www.linuxsir.org/main/doc/abs/HTML/untyped.html
4.3. Bash Variables Are Untyped
Example 4-4. Integer or string?
20 c=BB34
21 echo "c = $c" # c = BB34
22 d=${c/BB/23} # Substitute "23" for "BB".
23 # This makes $d an integer.
24 echo "d = $d" # d = 2334
|
|
2、
http://www.linuxsir.org/main/doc/abs/HTML/othertypesv.html
The space allotted to the environment is limited. Creating too many environmental variables or ones that use up excessive space may cause problems.
bash$ eval "`seq 10000 | sed -e 's/.*/export var&=ZZZZZZZZZZZZZZ/'`"
bash$ du
bash: /usr/bin/du: Argument list too long
|
|
3、
命令:basename(# Strips out path name info (see 'basename'))
[mdx@localhost abs-exercises]$ basename /home/mdx/abs-guide-3.7/ex15.sh
ex15.sh
4、比较:
16 if [ -n "$1" ] # Tested variable is quoted.
17 then
18 echo "Parameter #1 is $1" # Need quotes to escape #
19 fi
|
|
5、得到最后一个参数:
1 args=$# # Number of args passed.
2 lastarg=${!args}
3 # Or: lastarg=${!#}
4 # (Thanks, Chris Monson.)
5 # Note that lastarg=${!$#} doesn't work.
|
|
6、待查
If a script expects a command line parameter but is invoked without one, this may cause a null variable assignment, generally an undesirable result. One way to prevent this is to append an extra character to both sides of the assignment statement using the expected positional parameter.
1 variable1_=$1_ # Rather than variable1=$1
2 # This will prevent an error, even if positional parameter is absent.
3
4 critical_argument01=$variable1_
5
6 # The extra character can be stripped off later, like so.
7 variable1=${variable1_/_/}
8 # Side effects only if $variable1_ begins with an underscore.
9 # This uses one of the parameter substitution templates discussed later.
10 # (Leaving out the replacement pattern results in a deletion.)
11
12 # A more straightforward way of dealing with this is
13 #+ to simply test whether expected positional parameters have been passed.
14 if [ -z $1 ]
15 then
16 exit $E_MISSING_POS_PARAM
17 fi
18
19
20 # However, as Fabian Kreutz points out,
21 #+ the above method may have unexpected side-effects.
22 # A better method is parameter substitution:
23 # ${1:-$DefaultVal}
24 # See the "Parameter Substition" section
25 #+ in the "Variables Revisited" chapter.
|
|
7、在Example 4-6. wh, whois domain name lookup中,域名查询的服务器是无效的,可以换成:"wh-inn" ) whois $1@whois.internic.net;;
8、生词:
positional
notch