The Csh alias with perl one-liner evaluates when an alias is created, and not when an alias is used

I know, I know, I have to use a modern shell ... Anyway, here is the alias:

  alias p4client echo `p4 info | perl -ne 's/Client name: (.*)$/print $1/e'` 

I also know that probably the best way to get the p4 client name. This is just an example. So, can someone tell me a good and clean way to get this, to evaluate it when I call the alias, and not evaluate when the alias is created?

+3
source share
2 answers

The only trick is a backslash avoiding single quotes and surrounding everything else with single quotes:

alias p4client 'echo `p4 info | perl -ne '\''s/Client name: (.*)$/print $1/e'\''`'

Although perl can be simplified:

alias p4client 'echo `p4 info | perl -ne '\''print /Client name: (.*)/'\''`'

`` , ; ( perl , p4 ):

alias p4client 'p4 info | perl -ne '\''print /Client name: (.*)/s'\'

-, :

alias p4client "p4 info | perl -ne 'print /Client name: (.*)/s'"

, bash, , = p4client.

+7

, . :

alias p4client "echo "\`"p4 info | perl -ne 's/Client name: (.*)'\"\$"'/print '\"\$"'1/e'"\`

, csh - . . , , , . , .

1: , ! '\"\$"'

2: , . , bash . , csh, !

, , , . , , perl, , . , , :

% alias
4client echo `p4 info | perl -ne 's/Client name: (.*)'\$'/print '\$'1/e'`

'\$' , csh . . , \$ , .

+3

Source: https://habr.com/ru/post/1761648/


All Articles