Unix philosophy:
"Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface." - Doug McIlroy
#!/bin/bash
Text files that have been made executable (chmod +x file) can be made into scripts provided the first line begins with "#!" followed by the path of the program that will be fed the text file as it's stdin.
chmod +x
#!
#!/bin/tail -n+1
Bourne sh-compatible: sh, bash, ash, dash, ksh, zsh
sh
bash
ash
dash
ksh
zsh
C shells: csh, tcsh
csh
tcsh
perl
python
php
node.js
#!/bin/bash [-l] [-c 'command'] -l = login shell
#!/bin/bash [-l] [-c 'command']
-l
These scripts are read and executed by a bash shell on startup if it is a login shell (one that you login with or invoke with the -l option)
/etc/profile ~/.bash_profile ~/.bash_login ~/.profile
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
This script executed by any bash script that is not a login shell
~/.bashrc
This script is run when a login shell exits.
~/.bash_logout
Comments are denoted by an unquoted, unescaped `#' and continue to the end of the line.
[time [-p]] [!] <command1> [ | or |& <command2> ...]
[time [-p]] [!] <
> [ | or |& <
>
]
time
!
|
|&
'2>&1 |'
> ls -la | less
> ps aux | grep "^sbaker"
> man gcc 2> /dev/null | wc -l | awk '{ print $1/66 }'
> time sleep 1
one or more pipelines seperated by ;, &, &&, or ||
;
&
&&
||
command1 ; command2
command1 & command2
command1 && command2
if
; then
; fi
command1 || command2
if !
( list )
(
)
{ list; }
{
; }
{}
}
<
(( expr ))
((
))
$
(())
if (( a >= 0 && a <= 10 )); then echo "a in range 0-10"; fi
[[ expr ]]
[[
]]
[[ -f "$file" ]]; File $file exists and is regular [[ -z $str ]]; $str is an empty string [[ $str == wc ]]; $str matched wild-card pattern [[ $str =~ regex ]] $str matches regex pattern
[[ -f "$file" ]];
$file
[[ -z $str ]];
$str
[[ $str == wc ]];
[[ $str =~ regex ]]
command [&]>[>] file
[&]>[>]
ls -la > output ps ax >> output man gcc &>> output
command < file
wc -l < output
command <<[-] label ... label
<<[-]
'...'
$'...'
''
"..."
$"..."
""