Bash shell scripting for automation, pipelines, and system administration. Use for .sh files and Linux scripting.
Bourne Again SHell, the standard shell for Linux and macOS.
#!/bin/bash
NAME="World"
echo "Hello, $NAME!"
if [ -f "file.txt" ]; then
echo "File exists"
else
echo "File not found"
fi
No data types. Everything is a string.
count=10
echo $count
|: Pipe output of one command to input of next.>: Redirect output to file (overwrite).>>: Redirect output to file (append).cat file.txt | grep "error" > errors.log
Commands return 0 for success and non-zero for failure. Check with $?.
Do:
set -e (e)xit on errorset -u (u)nset variable usage is errorset -o pipefail to catch errors in pipes"$VAR" to handle spacesDon't:
ls output (use globs *)[ vs [[ (double brackets are safer)