Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

zsh newbie here... I find myself using a handful of long commands over and over again with slightly different arguments. For example:

rsync -havu --progress --rsh='ssh -l mylogin' some.machine.somewhere:/some/path /some/local/path

I'd like to be able to easily insert that command at my zsh prompt, and then navigate the command line to make the necessary changes to paths, hosts, and logins. I set up a zsh parameter:

FOO="rsync -havu --progress --rsh='ssh -l mylogin' some.machine.somewhere:/some/path /some/local/path"

Then I can expand $FOO at the prompt. However, the expanded command has all its spaces and quotations escaped with backslashes. Is there a way to make zsh not put the escape characters in the expansion?

I know I can search my history for similar commands and then edit those -- I'd still have to type the long thing out once in each new shell though. I'm also open to other ways I could accomplish my purpose... I could write a python script or something but that seems like a lot of overhead for a fairly simple task.

share|improve this question
    
try FOO=(rsync -havu --progress --rsh=\'ssh -l mylogin\' some.machine.somewhere:/so\ me/path /some/local/path) –  harish.venkat Jan 13 '13 at 2:53
    
Using a function is the right answer. Furthermore, you should probably not need --rsh. It's rare to specify a username explicitly when connecting with ssh. Usually, you would define an alias with the right username in your ~/.ssh/config. See ssh remote server on some port other than 22 without password for an example. –  Gilles Jan 14 '13 at 0:48
add comment

1 Answer

up vote 1 down vote accepted

I would recommend using a function that takes parameters for the options you commonly change. You can put this in your ZSH config and execute it interactively. Here is an example:

myrsync() {
   username=$1
   srchost=$2
   srcpath=$3
   destpath=$4
   rsync -havu --progress --rsh="ssh -l $username" "${srchost}:${srcpath}" "$destpath"
}

myrsync mylogin some.machine.somewhere /some/path /some/local/path
share|improve this answer
    
Many thanks for the suggestions, everyone. Giles, I somehow hadn't run across the .ssh/config option; I've set this up and it saves some typing. Thanks for the tip. I will likely create a function as suggested by jordanm and Giles, although one thing I like about using rsync from the prompt is keeping the syntax fresh in my memory for situations where I don't have my own configurations.... harish.venkat's suggestion is appealing but unfortunately did not work for me. –  Timothy W. Hilton Jan 14 '13 at 23:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.