all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ehud Karni" <ehud@unix.mvs.co.il>
Cc: emacs-devel@gnu.org
Subject: Re: sh-script.el and magic numbers
Date: Mon, 20 Jan 2003 09:59:16 +0200	[thread overview]
Message-ID: <200301200759.h0K7xGOH007624@beta.mvs.co.il> (raw)
In-Reply-To: <8del78n1ks.fsf@ast.cam.ac.uk> (message from Glenn Morris on Sun, 19 Jan 2003 23:48:19 +0000)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 19 Jan 2003 23:48:19 +0000, Glenn Morris <gmorris+mail@ast.cam.ac.uk> 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:ehud@unix.mvs.co.il                  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-----

  reply	other threads:[~2003-01-20  7:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-19  3:24 sh-script.el and magic numbers Luc Teirlinck
2003-01-19 12:47 ` Ehud Karni
2003-01-19 23:48   ` Glenn Morris
2003-01-20  7:59     ` Ehud Karni [this message]
2003-01-21  0:45       ` Luc Teirlinck
2003-01-21 10:49         ` Glenn Morris
2003-01-21 15:30           ` Luc Teirlinck
2003-01-21 15:44             ` Glenn Morris
2003-01-21 16:04               ` Luc Teirlinck
2003-01-21 17:23               ` Luc Teirlinck
2003-01-21 23:51                 ` Luc Teirlinck
2003-01-23  8:00                   ` Richard Stallman
2003-01-22  0:26                 ` Luc Teirlinck
2003-01-21 16:54           ` Kai Großjohann
2003-01-21 19:29             ` Luc Teirlinck
2003-01-21 20:00               ` Kai Großjohann
2003-01-22  8:41               ` Kai Großjohann
2003-01-22 14:18                 ` Luc Teirlinck
2003-01-22 20:51                   ` Luc Teirlinck
2003-01-23  1:12                   ` Kevin Rodgers
2003-01-20 16:45   ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200301200759.h0K7xGOH007624@beta.mvs.co.il \
    --to=ehud@unix.mvs.co.il \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.