Re: bash scripts and files



On 2007-12-31, michael <cs@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Thanks, probably the previous chapter ("she-bang") was of more use
but a useful ref. However, I'm still trying to understand why it's
not usual to have a she-bang for the .bash_profile and .bashrc files.
That documentation reads as if it's expected - they are scripts and
contain shell specific syntax.

Regular shell scripts could be called from any number of places. If
you're running a bash shell, you could run a csh or zsh or python
script. Similarly any of these scripts could be called from another
process, such as from a program written in C, or Lisp, or whatever. In
any of these cases the language of the script has no relation to the
environment it is called from. All the caller knows is that they are
executable files - any details are hidden. That means the pertinent
information needs to be stored in the script itself, and that has to
happen on the first line so the proper interpreter is invoked.

Imagine what would happen if you didn't do this. You call a script
from your terminal running bash, and that script is written in Perl.
Without the #! the terminal could either assume it's written in bash,
and choke on the syntax, or try and guess the language, which gets
hairy very quickly.

.bashrc and .bash_profile are different. They are only reasonably
invoked by a bash shell, so it is safe to assume they are written
using bash syntax. They are, after all, configuration files for bash,
so what other language would they be written in?

HTH,

Tyler


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > 1) They were out of context quotes, as the quotes came with no context. ... embed cpu instructions within a DOS/Windows batch script. ... that this also is possible with bash scripts. ... statement "It can execute the .com file as easily as a command.com ...
    (alt.lang.asm)
  • Re: [opensuse] Editting PATH variable
    ... SuSEconfig script ... ... not knowing what you options you used to install ... If your unfamiliar with Bash a good book is 'Learning the Bash Shell' by ... For Java use editing the PATH variable is NOT required... ...
    (SuSE)
  • Re: Command Line Interface
    ... >> should accept system commands only for an administrator. ... >> how should I supress the bash shell and launch my custom CLI ... > The script could run in a restricted shell and offer a menu of ... account, and either 1) change account password, 2) ...
    (comp.os.linux.misc)
  • Re: bash scripts and files
    ... you're running a bash shell, you could run a csh or zsh or python ... any of these cases the language of the script has no relation to the ... from your terminal running bash, and that script is written in Perl. ...
    (Debian-User)
  • Re: Convert Bash shell script to Korn shell script
    ... > The following bash script works fine to delete all files that are ... To execute this script, ... Start a bash shell: ... run the command "which find" ...
    (comp.unix.shell)