I am practicing with some Perl scripting and instead of typing the shebang each time I decided to make a basic Unix script that would create a new file with .pl extension and the shebang and then open the file for editing. What I tried was:
alias ep "echo '#! /usr/bin/perl' >> perl/\!*.pl; emacs perl/\!*.pl;"
But this causes an error if the file doesn’t already exist. I found that strange because I thought >> would append or create. So I changed the >> to > and this works but only if the file does not exist. If the file does exist it just crashes with an error. I tried adding an if statement but that also gave errors of syntax error and improper then. What I had for the if was:
alias ep "if [ ! -f perl/\!*.pl ] then echo '#! /usr/bin/perl' > perl/\!*.pl fi; emacs perl/\!*.pl;"
What am I missing? I am not too familiar with Unix scripting, but have a general knowledge.
you don’t want to do it like this; there are a lot of things to take account for (is that really a perl file if it exists already, etc)
you can do it instead directly with emacs
check this out: emacs skeletons and auto-insert