csh alias with variable number of arguments

后端 未结 3 428
孤街浪徒
孤街浪徒 2021-01-28 13:58

I would like to create a csh alias that performs one operation if invoked without arguments and a second operation if invoked with a single argument. Does anyone know how to do

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 14:50

    Easy to do - sorry I'm late to the party.

    alias iftest    'if (\\!:0 != \\!:$) echo "Last arg="\\!:$;if (\\!:0 == \\!:$) echo "No args given."'
    

    This merely checks whether the 0th argument (=the 'iftest' itself) and the last arguments are the same, and if they are, assumes there is no argument. This is, of course, not necessarily true, but hopefully works in praxis.

提交回复
热议问题