Bash Scripting Cheat Sheet: Variables, Loops & Functions
Essential bash scripting reference: variables, conditionals, loops, functions, string manipulation, and error handling.
Variables
name='World'\necho 'Hello $name'\nreadonly PI=3.14\ntoday=$(date +%Y-%m-%d)Conditionals
if [ -f 'file.txt' ]; then\n echo 'exists'\nelif [ -d 'dir' ]; then\n echo 'is directory'\nfiLoops
for f in *.txt; do echo $f; done\nwhile read line; do echo $line; done < file.txt
Try It Free
Use our free online tool — 100% client-side, no data leaves your browser.
Open Cron Parser