Quotation marks in filenames. Can they mess with quotation marks in shell code?
1
vote
1
answer
93
views
As far as I know, a safe and portable filename can consists of aA-zZ 0-9 hyphen and underscore only. At the same time, if we move away from the safe file-naming practices, we can use characters such as
!
?
$
%
"
'
/
and so on.
My question is about quotes, that is, "
and '
. Isn't it they are more dangerous than, for example, $
or /
? For example, if a filename contains spaces and we need to copy such a file, we would enclose its name quotes:
cp "file with spaces" folder_without_spaces
And because of this, I question myself: Isn't that quotes in a filename can mess with quotes in shell code sometimes?
For example, you have
aaa aaa ccc.txt
aaa "xxx" ccc.txt
and then you use
for f in *.txt; do mv "$f" backup_dir; done
and then "Bam!" - something broke. Nothing is broken actually in this particular example (at least on Zsh), but I hope you understood what I mean.
Asked by jsx97
(1347 rep)
Nov 6, 2024, 12:19 PM
Last activity: Nov 14, 2024, 10:39 PM
Last activity: Nov 14, 2024, 10:39 PM