读书笔记之 Advanced Bash-Scripting Guide Chapter 4 Introduction to Variables and Parameters
2013-04-15 23:40
218 查看
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对变量赋值时,会对等号后面的算术式进行算术运算,将运算后的值赋给变量。
mechanism (a newer method than backquotes).
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.
${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.
相关文章推荐
- Linker and Libraries Guide Chapter 1 Introduction to the Solaris OS Link Editors
- The Essential Guide to User Interface Design: An Introduction to GUI Design Principles and Technique
- The Definitive Guide to symfony | Chapter 15 - Unit And Functional Testing | symfony | Web PHP Framework
- Introduction to Languages and the Theory of Computation--Chapter 1 学习笔记
- Introduction to Algorithm(chapter 3 and 4)
- 《Computer Networking - Protocols in Aciton》读书笔记之Section 4.1: Joining the Internet: Introduction to IP and DHCP
- Introduction to Algorithm( chapter 9 and 10)
- AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Second Edition
- Chapter 3 Introduction to Objects and Input/Output
- chapter 1 introduction to computers,programs,and java
- Medians and Order Statistics - Introduction to Algorithm - Summary of Chapter 9
- Techno Security's Guide to E-Discovery and Digital Forensics: A Comprehensive Handbook
- Chapter 15 Introduction to Auto Layout
- More Detail On Workspaces And SmartParts (Introduction To The CAB/SCSF Part 16)
- Chapter10. UINavigationController - iOS Programming- The Big Nerd Ranch Guide 读书笔记
- OpenGL ES2.0 Programming Guide - chapter 3:An introduction to EGL
- 《Introduction to Information Retrieval》读书笔记(二)
- Database Systems: Introduction to Databases and Data Warehouses/Nenad Jukic-图书-亚马逊中国
- An Introduction to Change Points (packages: ecp and BreakoutDetection)
- A Beginner's Guide to Recurrent Networks and LSTMs