25Jun/090
Escaping Strings in a Shell Pipeline
A useful little sed script I wrote, which turned out to be much more useful than I expected. It simply takes a list of files, one per line, and outputs that same list, but with all the spaces and special characters escaped. It's mainly intended for use right between find and xargs, as in "find . -name 'asd' -print | shell-escape | xargs -I % echo %'
The list of characters is taken from IEEE Std 1003.1
#!/bin/sed -f
#
# Shell-Escape
# A very basic script to escape characters in the shell.
# Mainly intended for use in shell pipelines, right between
# 'find' and 'xargs'
#
s@\\@\\\\@g
s@ @\\ @g
s@'@\'@g
s@"@\\"@g
s@(@\\(@g
s@)@\\)@g
s@|@\\|@g
s@&@\\&@g
s@;@\\;@g
s@<@\\<@g
s@>@\\>@g
s@`@\\`@g
#
# Shell-Escape
# A very basic script to escape characters in the shell.
# Mainly intended for use in shell pipelines, right between
# 'find' and 'xargs'
#
s@\\@\\\\@g
s@ @\\ @g
s@'@\'@g
s@"@\\"@g
s@(@\\(@g
s@)@\\)@g
s@|@\\|@g
s@&@\\&@g
s@;@\\;@g
s@<@\\<@g
s@>@\\>@g
s@`@\\`@g












