Opening page…
Shell scripting, redirection, and command-line survival.
name="Ada"
echo "Hello $name"
count=$(ls | wc -l) # command substitution
readonly PI=3.14
unset nameif [ "$x" -gt 10 ]; then
echo "big"
elif [ "$x" -eq 10 ]; then
echo "ten"
else
echo "small"
fi
[ -f file ] # file exists
[ -d dir ] # dir exists
[ -z "$s" ] # string emptyfor i in 1 2 3; do echo $i; done
for f in *.txt; do echo "$f"; done
while read line; do
echo "$line"
done < file.txtcmd > out.txtStdout to file (overwrite)cmd >> out.txtAppend stdoutcmd 2> err.txtRedirect stderrcmd &> all.txtBoth streamscmd1 | cmd2Pipe outputcmd < in.txtStdin from filegrep -r "text" .Recursive searchfind . -name "*.js"Find filessed "s/a/b/g" fReplace textawk "{print $1}"Print first columnxargsBuild args from stdinchmod +x script.shMake executablegreet() {
echo "Hi, $1" # first arg
echo "All: $@" # all args
return 0
}
greet "world"
# script args: $0 name, $# count, $? last exit code