In Bash:
printf "%q" "hello\world" | someprog
for example:
printf "%q" "hello\world"
hello\\world
This could be used through variables too:
printf -v var "%q\n" "hello\world"
echo "$var"
hello\\world
More Related Contents:
- Which characters need to be escaped when using Bash?
- How to execute a bash command stored as a string with quotes and asterisk [duplicate]
- How to avoid heredoc expanding variables? [duplicate]
- How do I escape the wildcard/asterisk character in bash?
- Variable containing multiple args with quotes in Bash
- How do I pass in the asterisk character ‘*’ in bash as arguments to my C program?
- Is there an easy way to pass a “raw” string to grep?
- Bash script to cd to directory with spaces in pathname
- How do I properly escape data for a Makefile?
- How to match a single quote in sed
- How to echo a variable containing an unescaped dollar sign in bash
- escaping newlines in sed replacement string
- Exactly how do backslashes work within backticks?
- Make Bash handle variables like Batch
- How can I pipe stderr, and not stdout?
- Why start a shell command with a backslash?
- How to delete files older than X hours
- Bash: Strip trailing linebreak from output
- How can bash script do the equivalent of Ctrl-C to a background task?
- Running a Bash script over ssh
- How to resolve symbolic links in a shell script
- How to remove double-quotes in jq output for parsing json files in bash?
- Forward function declarations in a Bash or a Shell script?
- How can I convert tabs to spaces in every file of a directory?
- Multiple commands in an alias for bash
- How to use > in an xargs command?
- Casing arrow keys in bash
- Use GNU find to show only the leaf directories
- Get the name of the caller script in bash script
- Can bash script be written inside a AWS Lambda function