When I print a variable with one substring replacing another as described in this documentation, it behaves correctly:
stringZ='abc - 123'
echo $stringZ # abc - 123
echo ${stringZ/ - /test} # abctest123
However, if I get the string from a filename, the replacement is ignored completely:
for f in mp3/*; do
stringZ=$(basename $f)
echo $stringZ # abc - 123.txt
echo ${stringZ/ - /test} # abc - 123.txt
done
How can I replace a substring in a variable derived from a filename?
echo ... | hexdump -Cormp3/*' - '*to see if file matches pattern at allecho 'abc - 123.txt' | hexdump -Candecho $stringZ | hexdump -Cboth output00000000 61 62 63 20 2d 20 31 32 33 2e 74 78 74 0a