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 -C
ormp3/*' - '*
to see if file matches pattern at all – frostschutz Jun 12 '19 at 19:59echo 'abc - 123.txt' | hexdump -C
andecho $stringZ | hexdump -C
both output00000000 61 62 63 20 2d 20 31 32 33 2e 74 78 74 0a
– Keyslinger Jun 12 '19 at 20:13