Professional Documents
Culture Documents
1588669001478BashScriptingCheatSheet
1588669001478BashScriptingCheatSheet
Cheat-Sheet
for confidently writing shell-scripts with the bash
… to prevent users from running your script with the wrong interpreter
*** don’t forget to export variables which are to be used by subsequent commands ***
… special variables …
$? …returncode of last command $1..$9 … positional parameters
$$ … PID of actual shell/script use “shift” if you need more
$! … PID of last background process than 9 parameters
for-loop while-loop
stdout
stdin “normal” output goes here
command stderr
data to be read by
the command
used for error-messages
stdin is read from console / keyboard cmd > file ➜ write stdout to new
stdout and stderr are bound to console generated file
stdout and stderr are mixed cmd >> file ➜ append stdout to file
cmd 2> file ➜ write stderr to new
connecting commands: generated file
cmd 2>> file ➜ append stderr to file
cmd1 | cmd2 ➜ connect stdout of cmd1 cmd < file ➜ read stdin from file
to stdin of cmd2 cmd 2>&1 ➜ connect stderr and
stdout both to stdout
Tip: use xargs to copy stdout to next command-line as parameters: #> ls | xargs rm