lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [lmi-commits] odd/multiarch 768d4fc 4/7: Impede executing a sc


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] odd/multiarch 768d4fc 4/7: Impede executing a script that should instead be sourced
Date: Fri, 26 Apr 2019 02:18:29 +0200

On Fri, 26 Apr 2019 00:04:17 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2019-04-25 22:13, Vadim Zeitlin wrote:
GC> > On Thu, 25 Apr 2019 17:54:22 -0400 (EDT) Greg Chicares <address@hidden> 
wrote:
GC> [...]
GC> > GC> +++ b/set_arch.sh
GC> > GC> @@ -1,4 +1,4 @@
GC> > GC> -#!/bin/sh
GC> > GC> +#!/bin/sh this-script-must-be-sourced-not-run
GC> > 
GC> >  This is an interesting hack, but why do we need a hack at all here?
GC> > Wouldn't it be better to just remove the shebang line completely and, for
GC> > good measure, make the file non-executable?
GC> 
GC> I considered those ideas and others presented here:
GC>   
https://unix.stackexchange.com/questions/424492/how-to-define-a-shell-script-to-be-sourced-not-run/424498
GC> and preferred Ingo Karkat's answer because it's minimal and unobtrusive.
GC> I thought of twiddling the executable bit in addition, but that seemed
GC> unnecessary

 Well, a non-executable script can't be executed otherwise than by
explicitly doing "sh script.sh" and the shebang hack doesn't prevent this
way from executing it anyhow, so removing the executable bit seems exactly
equivalent.

GC> and a script with no shebang may be difficult for tools to recognize as
GC> a script.

 I could see this for a script without .sh extension, but I'm pretty sure
any tool would use the extension for recognizing the file type first.

GC> Ingo's "Feb 16 '18 at 9:25" comment mentions vim detection as well. Do
GC> you happen to know the magic setting to make vim detect 'GNUmakefile'
GC> as a makefile?

 It should really be detected automatically, I checked Vim 7.2, which is
the oldest version I still have immediate access to, and even it has the
line

        au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make

in its filetype.vim. Something in your Vim configuration must be overriding
this, but I don't know what. Please execute ":verbose set ft?" after
opening this file to see where is this option set (and what is its value).

 You could also try adding

        au BufNewFile,BufRead GNUmakefile setf make

to your .vimrc, but I'd rather determine what prevents the default filetype
detection from working.

 Good luck,
VZ


reply via email to

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