LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   tricky syntax for passing arguments in csh aliases (https://www.linuxquestions.org/questions/programming-9/tricky-syntax-for-passing-arguments-in-csh-aliases-713680/)

frerejacques 03-22-2009 09:51 PM

tricky syntax for passing arguments in csh aliases
 
I want to write a little time-saving alias for my .cshrc file that will move files and then cd to the directory I've moved them to. What I can't quite figure out is the syntax to say 'move all the arguments except the last one.' Here is what I have:

alias follow 'mv \!:1-$-1 \!:$; cd \!:$'

This actually seems to work, but it also gives me an irritating error:

mv: cannot stat `destinationdirectory/-1': No such file or directory

Similarly, I tried:

alias follow 'mv \!:*$#argv-1 \!:$; cd \!:$'

Again the move and cd are successful, but again there is an error:

mv: cannot stat `destinationdirectory/0-1': No such file or directory

I can guess that the problem is in getting the alias command to parse my expression the way I would like it to, but I can't figure out quite what will make it happy. Please let me know if you have any ideas.

Thanks,

Jeff

frerejacques 03-23-2009 03:20 PM

answered my own question
 
Okay, I came across the answer I was looking for on http://www.tcsh.org/tcsh.html/History_substitution.html. The syntax for "from argument x to the last argument, but one" is apparently just x-. So the alias I want is:

alias follow 'mv \!:1- \!:$; cd \!:$'


All times are GMT -5. The time now is 01:48 AM.