unixredhattcshaliases

how can I create an alias with arguments in multiple lines (like SH files)


i am on RedHat 6. i am trying to create an alias that takes arguments, but in order to make the alias more "readable" i want to create it in multiple lines (see code below) The alias is in a text file called "reg_aliases"

Example: instead of

   alias run_reg ' svn up ; cd project ; compile \!* ; cd project2 ; compile \!* ' 

desired:

   alias run_reg ' svn up 
   cd project ; compile \\!* ;
   cd project2 ; compile \\!* ; '

i tried to add "\" after each line but the last one, it did not work either.

Original Code:

alias comp_env_none 'arun -c -toppath \\!* -sncomp'
alias run_reg ' svn up $PROJECT; cd $PROJECT/work; comp_env_none $TOP -clean; cd $PROJECT/work_2 ; comp_env_none $TOP2 ; vmanager -gui \\!* ' 

tried to do this:

    alias run_reg ' svn up $PROJECT; \
    cd $PROJECT/work; comp_env_none $TOP -clean; \
    cd $PROJECT/work_2 ; comp_env_none $TOP2 ; \
    vmanager -gui \!* '

and it did not work. any suggestion on how to create such an alias ?


Solution

  • Having spent hours on this problem myself, I don't believe it is possible, since splitting the csh alias with \ into multi lines leads to evaluating each line separately and has some weird expansion rules.

    What I settled for in the end is to split my alias lines into variables then concatenate them in the alias definition. For your code, for example, I'd do this:

    set update_svn='svn up $PROJECT;'
    set setup_p1='cd $PROJECT/work; comp_env_none $TOP -clean;'
    set setup_p2='cd $PROJECT/work_2 ; comp_env_none $TOP2;'
    set open_gui='vmanager -gui \!*;'
    
    alias run_reg "${update_svn} ${setup_p1} ${setup_p2} ${open_gui}"