[sf-lug] Fwd: [UMALUG] bash scripting question
Michael.Paoli at cal.berkeley.edu
Sun Mar 2 23:58:41 PST 2008
A few items ...
The question is missing lots of details - e.g. "it runs fine,
except" leaves out many details that may be rather to quite relevant -
most notably, "So, ... when it doesn't run fine, exactly what is/isn't
it doing, how's it being invoked, what's the output and error output,
etc.?" Another highly relevant unanswered detail is the answer to "So,
... what exactly are you trying to do?". Of course there are many
other details that might be relevant, e.g.: permissions and ownerships
of the script and all ancestor physical directories, relevant bits of
the sudo (/etc/sudoers) configuration (and/or output of sudo -l),
version(s) of the shells and other programs involved, etc.
Be aware that <(list) construct would appear to not be currently
POSIX/SUS standards compliant, and thus may not be a particularly
portable construct (I notice it's in bash(1), but it's not in the
version of ash(1) I have at my fingertips ... ash(1) being a mostly
minimally POSIX(/SUS) compliant shell).
<< word (here-document) includes doing command and parameter
substitution - unless any character of word is quoted.
Within the here-document, stdin is redirected, so, that may be a bit
problematic for vimdiff - which generally would expect stdin to be a
tty device (when I try it, vimdiff gripes about that). Also, editors
and the like (e.g. vimdiff) may not work so well on named pipes / FIFOs
- they may read it in fine, or may be able to write it out fine - but
they generally won't be able to do both with the same pipe.
Anyway, ... at least when I test it, with suitable sudo and permissions
access, both versions of the script "work", with or without sudo ...
but in the case of using vimdiff within a here-document, vimdiff leaves
the tty settings messed up a bit afterwards (easy enough to fix with
^Jstty sane^J and then setting any desired specific stty preference
> Date: Sat, 1 Mar 2008 22:42:26 -0800
> From: "Kristian Erik Hermansen" <kristian.hermansen at gmail.com>
> Subject: [sf-lug] Fwd: [UMALUG] bash scripting question
> To: sf-lug at linuxmafia.com
> Can someone explain why removing the EOFs here breaks the script when
> using sudo?
> ---------- Forwarded message ----------
> From: Tyler Trafford <ttrafford at gmail.com>
> Date: Sun, 02 Mar 2008 00:23:33 -0500
> Subject: Re: [UMALUG] bash scripting question
> To: Linux Users Group <umasslug at ecs.umass.edu>
> Tyler Trafford wrote:
> > I have a script with a problem: it runs fine, except when I run it with
> > sudo. I can't figure out why that is.
> > Here's a simple example that demonstrates my problem:
> > -mytest.sh-
> > #!/bin/bash
> > vimdiff ~/.bashrc <(whoami)
> > ---
> It's odd, but changing the script like so:
> /bin/bash << EOF
> vimdiff ~/.bashrc <(whoami)
> -makes it work with and without sudo. I'd still like to know why if
> anyone has an idea.
> UmassLUG mailing list
> UmassLUG at ecs.umass.edu
More information about the sf-lug