Bash · lesson 8 of 30 · Decisions and loopsChoose with case
case compares a word with patterns; *) takes the rest.
08-case.sh Download 08-case.sh
#!/usr/app/TurboShell/bin/bash
for file in "$@"; do
case ${file,,} in
*.jpg | *.png) echo "$file: photo" ;;
*.mov | *.mp4) echo "$file: film" ;;
[0-9]*) echo "$file: starts with a digit" ;;
*) echo "$file: other" ;;
esac
done
Terminal
$ bash 08-case.sh beach.JPG trip.mp4 2027.txt notes.txt
beach.JPG: photo
trip.mp4: film
2027.txt: starts with a digit
notes.txt: otherExercise
Add music files.