Bash · lesson 16 of 30 · Data, functions and the command lineCut text without other commands
# cuts from the front, % from the end, / replaces and ,, makes small letters.
16-text.sh Download 16-text.sh
#!/usr/app/TurboShell/bin/bash
path=photos/Holiday-2027.JPG
file=${path##*/}
echo "file: $file"
echo "folder: ${path%/*}"
echo "ending: ${file##*.}"
echo "without ending: ${file%.*}"
echo "length: ${#file}"
echo "first 7: ${file:0:7}"
echo "small: ${file,,}"
echo "replaced: ${file/2027/2028}"
echo "default: ${missing:-nothing here}"
Terminal
$ bash 16-text.sh
file: Holiday-2027.JPG
folder: photos
ending: JPG
without ending: Holiday-2027
length: 16
first 7: Holiday
small: holiday-2027.jpg
replaced: Holiday-2028.JPG
default: nothing hereExercise
Change the ending of a file name to .bak.