0

For example, I want to create an alias to remove duplicate lines:

alias rm.dup  'perl -ne 'print unless $dup{$_}++;''

When source .cshrc, it reports: "dup: Undefined variable."

If change it to

alias rm.dup  'perl -ne 'print unless \$dup{$_}++;' \!* &'

It reports: "!* &: Command not found."

And also tried

alias rm.dup  'perl -ne 'print unless \$dup{$_}++;''

Reports: ": Command not found."

What's the general rule of using variable with alias?

1 Answer 1

1
alias rm.dup  'perl -ne '\''print unless $dup{$_}++'\'' \!* &'

Since one cannot embed a single quote within single quotes, so one way is to break out of the single quote, slip in a literal quote, then restart the quotes.

'perl -ne '\''print unless $dup{$_}++'\'' \!* &'
|---------|B |-----------------------|D |------|
     A                   C                  E

Another way is:

alias rm.dup  'perl -ne "print unless "\$"dup{"\$"_}++" \!* &'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.