[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sh-script.el and magic numbers
From: |
Ehud Karni |
Subject: |
Re: sh-script.el and magic numbers |
Date: |
Mon, 20 Jan 2003 09:59:16 +0200 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, 19 Jan 2003 23:48:19 +0000, Glenn Morris <address@hidden> wrote:
>
> The main Emacs-related gripe I have about adding it is that I like to use
>
> (add-hook 'after-save-hook
> 'executable-make-buffer-file-executable-if-script-p)
>
> which makes files that contain #! magic executable on save. So if I put
> #!/bin/bash in my ~/.bashrc, for example, Emacs insists on making it
> executable, which annoys me, as it's not *meant* to be executed.
The solution to that is simple. Don't put the "#!" magic number,
instead change the 1st line to something like this:
# <your comment> -*- mode: sh -*-
> > You can use it in sourced files (both in sh/bash and csh/tcsh).
>
> You can't *use* it. You can put it in the file and it doesn't do anything -
> doesn't seem very useful to me.
That's what I meant, that it does not interfere with sourcing.
It is useful. It is clearer to the reader which shell will run it.
> I note that none of the system config files in the RedHat distribution I'm
> currently using have it.
I don't think so, take a look at the scripts in /etc/init.d (almost all
have #!/bin/bash in them FOR A REASON (see below).
> > It is good programming practice to add it.
>
> Why?
Because if you don't have the magic number, when you run the script,
it is run in the CURRENT shell which may be bash, but also any of the
other useful shells (ksh, zsh, csh/tcsh, etc.). The differences may
be very small (ash vs. bash) or too large to run (bash vs. csh).
Most of the configuration scripts are sourced (it is run by the current
shell) so specifying shell does not do anything. The init scripts (in
/etc/init.d) may be run (and are run) by any shell without problems.
Some are intended for very specific shell (.bashrc, .cshrc), although
it is not necessary to put the magic number, it is advisable for
debugging purposes (you can run it as normal script to check it).
One last remark: Don't generalize from the GNU/Linux to all UNIX/POSIX
systems. e.g. In GNU/Linux sh is synonym for bash, but there are POSIX
systems where this is not true.
Ehud.
- --
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
mailto:address@hidden Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)
iD8DBQE+K6xTLFvTvpjqOY0RArojAKCKcNk6/9fLxyigpCtWQrOl40DS1gCeJHYD
xuE88KJ4f3HB2046d9u5Ytc=
=3yJ4
-----END PGP SIGNATURE-----
- sh-script.el and magic numbers, Luc Teirlinck, 2003/01/18
- Re: sh-script.el and magic numbers, Ehud Karni, 2003/01/19
- Re: sh-script.el and magic numbers, Glenn Morris, 2003/01/19
- Re: sh-script.el and magic numbers,
Ehud Karni <=
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/20
- Re: sh-script.el and magic numbers, Glenn Morris, 2003/01/21
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/21
- Re: sh-script.el and magic numbers, Glenn Morris, 2003/01/21
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/21
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/21
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/21
- Re: sh-script.el and magic numbers, Richard Stallman, 2003/01/23
- Re: sh-script.el and magic numbers, Luc Teirlinck, 2003/01/21
- Re: sh-script.el and magic numbers, Kai Großjohann, 2003/01/21