I want to write one script with my alias but not able to add bang line in my script with echo command. I tried these ways:
alias wnc 'echo "#!/bin/csh " > cshCMD.csh; echo "ncl" >> cshCMD.csh; chmod +x cshCMD.csh; ' alias wnc "echo '#!/bin/csh ' > cshCMD.csh; echo 'ncl' >> cshCMD.csh; chmod +x cshCMD.csh;"
If I run these lines without alias then they work for me.
echo "#!/bin/csh " > cshCMD.csh; echo "ncl" >> cshCMD.csh; chmod +x cshCMD.csh;
With direct typing and using command I’ll get data in file cshCMD.csh as:
#!/bin/csh
ncl
while when I use alias on command line as
wnc
I got this message :
/bin/csh: Event not found
Advertisement
Answer
You need a !
in the expansion of your alias, so you must use \!
when defining it. The first backslash disappears during processing of the alias-defining command and the second one protects the !
when the alias runs.