SHELL-QUOTE(1p) | User Contributed Perl Documentation | SHELL-QUOTE(1p) |
shell-quote - quote arguments for safe use, unmodified in a shell command
shell-quote [switch]... arg...
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples.
ssh host touch 'hi there' # fails
It creates 2 files, hi and there. Instead, do this:
cmd=`shell-quote touch 'hi there'` ssh host "$cmd"
This gives you just 1 file, hi there.
eval set -- `find -type f -print0 | xargs -0 shell-quote --`
debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" }
With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can.
user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args"
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions.
Roderick Schertler <roderick@argon.org>
2017-08-04 | perl v5.26.0 |