diff options
author | Jonas Smedegaard <dr@jones.dk> | 2016-10-22 19:01:41 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2016-10-22 23:59:09 +0200 |
commit | 6aa2a9af5e24ddfed681fd7f1d68013abb6c471f (patch) | |
tree | ffbf0f085b88f815353aaed7d630878f9cfd1c85 /xsh | |
parent | a18858bcc1048d7c303f8d6c34f640713cfa489a (diff) |
Fix shell-wrap as needed, singlequote-escaped.
Diffstat (limited to 'xsh')
-rwxr-xr-x | xsh | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -6,6 +6,18 @@ usage() { echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] command...]" } +# origin: http://stackoverflow.com/a/34515468 +quote_args() { + local sq="'" + local dq='"' + local space="" + local arg + for arg; do + echo -n "$space'${arg//$sq/$sq$dq$sq$dq$sq}'" + space=" " + done +} + # Initial setup SU='' SUDO='' @@ -31,16 +43,15 @@ done [ $# -gt 0 ] || set -- /bin/bash -# FIXME: needs shell wrapper (provided by SSH but not in local use) -[ -z "$SU" ] || set -- "echo -n 'Changing to root...: '; su -c \"cd; "$@"\"" +[ -z "$SU" ] || set -- su -c "cd; $(quote_args "$@")" +[ -z "$SU" ] || set -- sh -c "echo -n 'Changing to root...: '; $(quote_args "$@")" [ -z "$SUDO" ] || set -- sudo -i -- "$@" # Pause for a moment if verbose -# FIXME: needs shell wrapper (provided by SSH but not in local use) -[ -z "$V" ] || set -- "$@"\; sleep 4 +[ -z "$V" ] || set -- sh -c "$(quote_args "$@"); sleep 4" -[ -z "$HOST" ] || set -- ssh -t${X:+ -X}${V:+ -v}${PORT:+ -p "$PORT"} $HOST "$@" +[ -z "$HOST" ] || set -- ssh -t${X:+ -X}${V:+ -v}${PORT:+ -p "$PORT"} $HOST "$(quote_args "$@")" [ -z "$V" ] || echo "$@" [ -z "$V" ] || sleep 4 |