Shell study notes
Friday, December 6, 2013
Wednesday, December 4, 2013
Expansion
http://linuxcommand.org/lc3_lts0080.php
command substitution:
$(command)
`command`
Arithmetic expansion:
c-style integer expansion: ((expression))
Integer expansion: $[ ]
bash builtin let command: let counter="counter + 1"
subprocess expr: counter=`expr counter + 1' (must have space around operator)
Quoting:
double quote: all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are “$”, “\” (backslash), and “`” (back- quote). This means that word-splitting, pathname expansion, tilde expansion, and brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution are still carried out.
Single quote: suppress all expansions
command substitution:
$(command)
`command`
Arithmetic expansion:
c-style integer expansion: ((expression))
Integer expansion: $[ ]
bash builtin let command: let counter="counter + 1"
subprocess expr: counter=`expr counter + 1' (must have space around operator)
Quoting:
double quote: all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are “$”, “\” (backslash), and “`” (back- quote). This means that word-splitting, pathname expansion, tilde expansion, and brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution are still carried out.
Single quote: suppress all expansions
Signal
Kill: a command used to send signal to a process
signal names can be found by kill -l
SIGTERM (15) least dangerous
SIGKILL (9)
SIGSTOP (17,19,23)
signal names can be found by kill -l
SIGTERM (15) least dangerous
SIGKILL (9)
SIGSTOP (17,19,23)
Monday, December 2, 2013
Regular Expression
a good place to study: http://www.zytrax.com/tech/web/regex.htm#intro
Bracket, range, negation
[] indicate a rage, one and only one matching
- range
^ inside [] means negate the expression
Anchors
^ Beginning
$ Ending
. Any char at THIS position
Iteration
? 0 or 1
* 0 or more
+ 1 or more
{n} exactly n times
{n,m} appears at least n, at most m times
{n,} at least n times
Other
() grouping
| or, alternation
Abbreviations
\d digit
\D not digits
\s space
\S not space
\b boundary of words
\B not boundary
\w 0-9, A-Z, a-z
\W not \w
Bracket, range, negation
[] indicate a rage, one and only one matching
- range
^ inside [] means negate the expression
Anchors
^ Beginning
$ Ending
. Any char at THIS position
Iteration
? 0 or 1
* 0 or more
+ 1 or more
{n} exactly n times
{n,m} appears at least n, at most m times
{n,} at least n times
Other
() grouping
| or, alternation
Abbreviations
\d digit
\D not digits
\s space
\S not space
\b boundary of words
\B not boundary
\w 0-9, A-Z, a-z
\W not \w
Basic
What is shell:
Provide User interface to access Kernel services.
An out layer between user and system kernel.
Need to read:
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html (I like this one)
http://tldp.org/LDP/abs/html/index.html
https://developer.apple.com/library/mac/DOCUMENTATION/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html
http://www.gnu.org/software/bash/manual/bashref.html#What-is-Bash_003f
http://www.thegeekstuff.com/tag/bash-tutorial/
Shell types:
sh
bash
csh
tcsh
ksh
Configure profile: (create them if needed)
System wide
/etc/profile
/etc/bashrc
Individual user:
~/.bash_profile
~/.bashrc
~/.bash_login
~/.bash_logout
Variables: Case sensitive, Capital by convention, No Space around equal sign
Global v.s. Local
Types: String, Integer, Constant, Array
Command Substitution: allows the output of a command to replace the command itself
Provide User interface to access Kernel services.
An out layer between user and system kernel.
Need to read:
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html (I like this one)
http://tldp.org/LDP/abs/html/index.html
https://developer.apple.com/library/mac/DOCUMENTATION/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html
http://www.gnu.org/software/bash/manual/bashref.html#What-is-Bash_003f
http://www.thegeekstuff.com/tag/bash-tutorial/
Shell types:
sh
bash
csh
tcsh
ksh
Configure profile: (create them if needed)
System wide
/etc/profile
/etc/bashrc
Individual user:
~/.bash_profile
~/.bashrc
~/.bash_login
~/.bash_logout
Variables: Case sensitive, Capital by convention, No Space around equal sign
Global v.s. Local
Types: String, Integer, Constant, Array
Command Substitution: allows the output of a command to replace the command itself
$(command) preferred
`command`exercise:
http://www.freeos.com/guides/lsst/ch08.html
Subscribe to:
Posts (Atom)