Shell
Variables
Section titled “Variables”$PS1: prompt$HOME: base directory$IFS: separator$0: name of the script$1,$2: arguments$*: list of arguments - truncated with first char of$IFS$@: list of arguments - as separated args$#: number of arguments$?: last return code
man bashcan explain a lot
Variable escaping
Section titled “Variable escaping”#!/bin/shx="hello world"
# a variable without quote can be two separate argumentsprintf '%s\n' $x# hello# world
# a variable with quote will be one argument (exception exists for $@)printf '%s\n' "$x"# hello world
# the $IFS char will be replaced by space# you can also change the IFS temporarly
IFS='w'printf '%s\n' $x# hello# orld
# note the space after hello and the missing 'w'
printf '%s\n' "$x"# hello world
IFS=' ' # reset the IFSTest command
Section titled “Test command”test -f myfile # return 1touch myfiletest -f myfile # return 0
# You can also use the test binary with the '[' binary - it's the same form# but you need a closing ']'
[ -f myfile ]