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 expected. 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. Bob 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.