Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^4: csh, alias, perl & quotesby Smylers (Pilgrim) |
on Jun 17, 2005 at 14:57 UTC ( [id://467749]=note: print w/replies, xml ) | Need Help?? |
alias rfw "perl -ne '/\$mail_cmd/ || print;' \!^" You need quoting at several levels:
Each level may add quoting characters which themselves need protecting at the previous level, so let's take them in reverse. Ignore aliasing and the shell for the moment, you want a Perl program that consists of: /\$mail_cmd/ || print;That backslash has to be there so that Perl treats the dollar sign as a literal dollar, rather than trying to interpolate a Perl variable. However the semicolon is unnecessary and the double bars can be replaced by something else, so let's get rid of those — quoting in C-Shell aliases is rather broken, so minimizing the number of characters that need protecting is a good start. This'll work: print unless /\$mail_cmd/That needs quoting as a whole for passing to the shell. It contains a dollar sign, so double quotes can't be used, because in the C Shell dollars in double quotes are always acted upon by the shell. So let's use single quotes for this: perl -wne 'print unless /\$mail_cmd/'Now we want to set up an alias with that as the value. Spaces in an alias definition don't usually matter: even if the entire definition is parsed as a single parameter now, it's going to get split on spaces when it gets expanded. The only special characters in the above which need protecting are the single quotes, the backslash, and the dollar. So one way of writing the alias is simply to stick a backslash before each of those characters (and before the exclamation mark in the alias's placeholder): alias rfw perl -wne \'print unless /\\\$mail_cmd/\' \!^Again because of the dollar sign there's no point in trying to use double quotes. But you could use single quotes to protect everything except for the single quotes. There's only one set of single quotes in the alias expansion, so you could put a new set of single quotes just inside them (to protect everything that's between them) and just put backslashes before each of the outer single quotes (to protect them): alias rfw perl -wne \''print unless /\$mail_cmd/'\' \!^Smylers
In Section
Seekers of Perl Wisdom
|
|