读书笔记之 Advanced Bash-Scripting Guide Chapter 4 Introduction to Variables and Parameters

1. Note that $variable is actually a simplified form of ${variable}.
2. An uninitialized variable has no value, however it acts as if it were 0 in an arithmetic operation. This is undocumented (and probably non-portable) behavior, and should not be used in a script.(P31)
3. 此处a的值为21, 使用let对变量赋值时,会对等号后面的算术式进行算术运算,将运算后的值赋给变量
let a=16+5
echo "The value of \"a\" is now $a."
4. 注意代码中的注释。Variable assignment using the $(...) mechanism (a newer method than backquotes).
a=`ls -l` # Assigns result of 'ls -l' command to 'a'
echo $a   # Unquoted, however, it removes tabs and newlines.
echo
echo "$a" # The quoted variable preserves whitespace.
5. If a script sets environmental variables, they need to be "exported", that is, reported to the environment local to the script. This is the function of the export command. A script can export variables only to child processes.
6. Arguments passed to the script from the command line: $0, $1, $2, ..., ${10}, ${11},...  $0 is the name of the script itself. The special variables $* and $@ denote all the positional parameters. $# Number of args passed (不包括脚本本身).
7. The shift command reassigns the positional parameters, in effect shifting them to the left one notch. The old $1 disappears, but $0 (the script name) does not change.  The shift command works in a similar fashion on parameters passed to a function.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值