Reputation: 9298
I am writing a shell program to output another shell program to be evalled later. Is there some common shell program to print shell escaped for a string?
Upvotes: 1
Views: 177
Reputation: 701
I'm not sure I understand you question. But the %q
option of printf
might be what you are looking for.
%q Output the corresponding argument in a format that can be reused as shell input
printf %q 'C:\ProgramFiles is a Windows path;'
outputs C:\\ProgramFiles\ is\ a\ Windows\ path\;
(In this example, simple quotes are needed – comment of Gordon Davisson – but this doesn't matter if you print from a variable or the output of a command.)
Upvotes: 2
Reputation: 4499
You could use single quoted string as this is evaluated without any substitution.
For example the following commands are equivalent
cat abc\ hi.txt
cat 'abc hi.txt'
Upvotes: 0