I need to write a script to show me all the alias I’ve set in certain config files like .tcshrc and some private script in case that I forget the meaning of alias like “a” ,
“b” , etc . the format of the aliases in the config file is either alias a “content of alias a” or alias b ‘content of alias b’ .
the code I wrote is as below :
#! /usr/bin/perl
open ( F , "<" , ".tcshrc" ) or die "can't open it; $! " ;
while ( <F> ) {
if ( /\b(alias\s+\w+\s+[\'\"][^\'\"]*[\'\"])/ ) {
print $1 ;
}
but the code doesn’t work. So could any of you have a look at the code and tell me what’s wrong with the reqex?
@Karel Bílek
Yes, I missed the backslash at the second s, now it worked. but I’m still interested to know whether there is a better way to write the regex.
@Charles
the lines I want to match is like
alias a 'ls -l'
alias b "rm *"
You may not need a script for this. In tcsh, you can just execute
aliaswithout any arguments and it will list all alias definitions. Or to look up a particular alias just runalias [name]where NAME is the name of the alias.For example:
If you want to go the other way to, say, remember which aliases map to
ls, you can usegrepfor that:This also works in other shells like bash and zsh.