Sort of OT - perl files

P

Phil Healey

Here goes: I looked all over the place, and I think I'm still too far
down on the "steep part of the learning curve" to figure this out.

When writing perl scripts, I touch the filename and then chmod a+x it so
that it is executable with './'. Then I edit the new file. What I
normally do is something like this:

touch file.pl; chmod a+x file.pl; vim file.pl

What I want to do is add an alias to my .bashrc file so I can enter one
command to take care of the above.

alias touchpl [filename] = 'touch [filename]; chmod a+x [filename]; vim
[filename]'

is what I want to be able to do, but I don't know how to get it to
incorporate whatever filename I use.

Any ideas?
 
P

Peter Jones

A couple of questions:


Should this be #!/bin/bash ?

No. Yes. Maybe. There is a good chance (on most Linux systems) that
/bin/sh is simply a link to /bin/bash, with the caveat that bash will
attempt to mimic the operation of the original Bourne shell when called
as 'sh'. However, when searching google to clarify my own reasons for
using /bin/sh rather than /bin/bash I found the following:

: It doesn't. This is straight Bourne shell. You really should change
: that
: #!/bin/bash
: into
: #!/bin/sh
: You should _never_ place such a dependency on a particular shell
: dialect into a script unless you really really _need_ some oddball
: extension. Write portable scripts and you'll have less trouble in the
: long run, as will others trying to use your scripts.

(https://www.redhat.com/archives/redhat-list/1998-October/msg00584.html)

which essentially confirms what I had been led to believe. Unless you
have a script which specifically requires bash, it is generally best to
use "#!/bin/sh" as meaning "the generic system shell". All of which is
getting rather OT, and I'd recommend further questioning of this point
be directed to comp.unix.shell :)
touch $1
chmod a+x $1
vim $1

And just to get this straight: I write the script and save it as
'touchpl' (or whatever) and from then on I just type 'touchpl [file]'
at the shell prompt and voila?

Indeed. The '$1' in a shell script represents the first argument -- in
this case, '[file]'...

Apologies to all for the off-topic spiel...

Pete.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top