In Bash, v.4.3.11(1) I have this sample code:
#!/bin/bash
dir=("/home/user/Documents/" "/home/user/Music/" "/home/user/Videos/" \
"/home/user/Photos/")
baseDir="/home/user/"
for i in "${!dir[@]}"
do
niceName=${dir[$i]#"$baseDir"} # removes baseDir from front part
printf "%s\n" "${niceName%"/"}" # also removes trailing slash from end
done
Is there a way to combine the two commands in one and have only the printf within the for loop? (preferably without resorting to awk or sed, but ok, if inevitable).
I have tried various combinations but I am ending up with "bad substitution" errors.
For example, printf "%s\n" "${niceName=${dir[$i]#"$baseDir"%"/"}"
is not working for me.