Prefer executing command line commands via script and not the command line. Benefits:
- Easy to double check work.
- If a modification is needed, the script can be quickly rerun.
- Teaches scripting as you go.
- Can write the script in an IDE such as CLion with the Shell Script plugin which:
- Downloads ShellCheck on request which lints and provides best practices in realtime.
- Downloads shfmt on request which formats shell scripts.
- Provides code completion, refactoring, quick documentation, and run/debug configurations.
Bash
Bash is the Bourne Again Shell.
Written for the GNU Project to replace the Bourne Shell (sh).
Default shell of most Linux distrobutions.
Check return code:
echo $?
Looping
for VARIABLE in 1 2 3
do
echo $VARIABLE
done
Editing Files
echo “replacement” > file
echo “append” >> file
Scripting
#!/bin/bash
# uses bash as opposed to the user's shell.
set -e # makes the script end on error
Keys Shortcuts