简体   繁体   中英

Bash alias with nested quotations

how can I set up an alias for this command? (because it has multiple quotations)

rsync -azv -e 'ssh -o "ProxyCommand ssh -A some@place -W %h:%p"' user@xxx:/data/as ~/

Just use single quotes and replace each single quote with '\\'' .

alias XYZ='rsync -azv -e '\''ssh -o "ProxyCommand ssh -A some@place -W %h:%p"'\'' user@xxx:/data/as ~/'

Or, use a function instead of an alias

XYZ () {
    rsync -azv -e 'ssh -o "ProxyCommand ssh -A some@place -W %h:%p"' user@xxx:/data/as ~/ "$@"
}

It's more flexible and gives you a chance to parameterize the command later.

Escape the inner double quote and quote everything with double quote because you cannot escape single quote but only double quote. (sounds a bit funny)

alias foobar="rsync -azv -e 'ssh -o \"ProxyCommand ssh -A some@place -W %h:%p\"' user@xxx:/data/as ~/"

You might want to check this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM