Sample Header Ad - 728x90

shell: Quote string with single quotes rather than backslashes

6 votes
4 answers
7169 views
How can I quote a string with single quotes? Eg, I can do: $ printf "%q\n" 'two words' two\ words $ Is there a way to get a single- (or double-) quoted string as output, ie: $ MAGIC 'two words' 'two words' $ I find the single-quoted version much easier to read. I'd like an answer which works for {ba,z}sh. POSIX shell would be a bonus.
Asked by Tom Hale (32892 rep)
May 23, 2018, 04:14 AM
Last activity: Dec 15, 2024, 05:10 PM