Properly escape a string variable that contains special characters to be used in a shell script?
0
votes
0
answers
206
views
I feel dumb for asking such a simple question but Im absolutely stuck on this one. I've search everywhere, tried several methods to escape or properly quote this variable, but no matter what when I run this in a shell script I get the following error:
stat: cannot statx 'This is an odd | filename | (name).m4a' : No such file or directory
The file exists in the directory this is being run at.
#!/bin/bash
FILENAME="This is an odd | filename | (name).m4a"
FILESIZE=$(stat "%s" "$FILENAME")
echo "Size of $FILENAME = $FILESIZE bytes."
When I run this on the commandline it works just fine:
$ stat "%s" 'This is an odd | filename | (name).m4a'
Asked by ProfessionalAmateur
(3275 rep)
Sep 21, 2023, 02:26 PM