Noțiuni de bază
Introducere
aceasta este o referință rapidă pentru a începe cu Bash scripting.
- aflați bash În y minute (learnxinyminutes.com)
-  Ghid de Bash (mywiki.wooledge.,td> 
${FOO:(-3):3}Substring from the right LengthExpression Description ${#FOO}Length of $FOOManipulationDefault valuesOmitting the :removes the (non)nullity checks, e.,g.${FOO-val}expands tovalif unset otherwise$FOO.,/div>Expression Description $#Number of arguments $*All arguments $@All arguments, starting from first $1First argument $_Last argument of the previous command See Special parameters.,043f44″> 
File conditions
Example
# Stringif ]; then echo "String is empty"elif ]; then echo "String is not empty"else echo "This never happens"fi# Combinationsif ]; then ...fi# Equalif ]# Regexif ]if (( $a < $b )); then echo "$a is smaller than $b"fiif ]; then echo "file exists"fiArrays
Defining arrays
Fruits=('Apple' 'Banana' 'Orange')Fruits="Apple"Fruits="Banana"Fruits="Orange"Working with arrays
Operations
Iteration
for i in "${arrayName}"; do echo $idoneDictionaries
Defining
declare -A soundssounds="bark"sounds="moo"sounds="tweet"sounds="howl"Declares sound as a Dictionary object (aka associative array).,
de Lucru cu dicționare
Repetare
Itera peste valorile
for val in "${sounds}"; do echo $valdoneItera peste tastele
for key in "${!sounds}"; do echo $keydoneOpțiuni
Opțiuni
set -o noclobber # Avoid overlay files (echo "hi" > foo)set -o errexit # Used to exit upon error, avoiding cascading errorsset -o pipefail # Unveils hidden failuresset -o nounset # Exposes unset variablesGlob opțiuni
Set GLOBIGNORE ca un colon listă separată de modele pentru a fi eliminate de la globmatches.,>
!-nnth most recent command!nnth command in history!<command><command> Operations
!! and !$ can be replaced with any valid expansion.,aec7ee5e”>
)
!^!$!!:n-m!!:n-$nth token to last from most recent command!! can be replaced with any valid expansion i.,e. !cat, !-2, !42, etc.,
Special variables
| Expression | Description | 
|---|---|
| $? | Exit status of last task | 
| $! | PID of last background task | 
| $$ | PID of shell | 
| $0 | Filename of the shell script | 
See Special parameters.,
pwd # /home/user/foocd bar/pwd # /home/user/foo/barcd -pwd # /home/user/fooCheck for command’s result
if ping -c 1 google.com; then echo "It appears you have a working internet connection"fiGrep check
if grep -q 'foo' ~/.bash_history; then echo "You appear to have typed 'foo' in the past"fi



