[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should this be this way?

From: Bob Proulx
Subject: Re: Should this be this way?
Date: Thu, 28 Feb 2013 09:55:01 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Chet Ramey wrote:
> Linda Walsh wrote:
> > Greg Wooledge wrote:
> >>> How often, when at a terminal, do you type #!/bin/bash before every line?
> >>
> >> When I've put the contents into a file?  Every. single. time.
> > ---
> > Then when I press 'v' to edit the command line in a text editor --
> > maybe 'bash' should insert such a line?  It's converted your command line
> > into an editable file.  But it hasn't put the #!/bin/bash at the front.
> This is a bad example.  The file that is the result of the vi-mode `v'
> command is run as if it were sourced with `.'.  It's not run as if it
> were a shell script.

Ah!  There is the answer.  Don't run it as a script.  Always source
these files instead.  ". ./file"  When sourced they will run in the
context of the current bash shell and the behavior will be as

I say that somewhat tongue-in-cheek myself.  Because sourcing files
removes the abstraction barriers of a stacked child process and
actions there can persistently change the current shell.  Not good as
a general interface for random actions.  Normal scripts are better.


Who still remembers when if the exec(2) failed then the shell
examined the first character.  If it was a '#' then shell ran the file
through csh.  If ':' then through ksh.  If neither then sh.  This may
have been a local hack though.  Clearly the Berkeley #! hack is better.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]