Bash scripts: from a loop to a robust script
Learn to write scripts that don't break on spaces in file names, empty arguments or failures — and schedule them with cron.
- A loop with a countereasy
- Required Argument Checkeasy
- Check whether a file existseasy
- Repeat an action N timeseasy
- Argument with a default valueeasy
- Split a path into name and directoryeasy
- Count Non-Empty Lineseasy
- Branching with && and ||medium
- Quotes and spacesmedium
- Output to both the screen and a logmedium
- stdin, stdout, stderr and pipesinterview questioneasy
- Process files with spaces in their namesmedium
- Sum of argumentsmedium
- Sum of numbers from a filemedium
- Find the maximum in a filemedium
- Command Router Scriptmedium
- Validate input against a patternmedium
- Array in bashmedium
- A function that prints its resultmedium
- A script with flags via getoptsmedium
- A script with trap cleanupmedium
- Backup Script with the Date in the Filenamemedium
- Limit execution timeeasy
- Wait for a background job and grab its exit codemedium
- Don't let the script run twicehard
- Retry with increasing delayshard
- An evening report on a scheduleeasy
- Fix PATH for a cron jobmedium
- Publishing doesn't notice the errormedium
- A size-counting script: zero warningsmedium
- A robust scripthard