[sf-lug] Fwd: [UMALUG] bash scripting question

Tyler Trafford ttrafford at gmail.com
Mon Mar 3 07:02:29 PST 2008


I appears that my original message got snipped when it was forwarded on,
here is the output of running the orginal script with sudo:

$ sudo ./mytest.sh                                                               
./mytest: line 2: syntax error near unexpected token `('                         
./mytest: line 2: `vimdiff ~/.bashrc <(whoami)'



Michael Paoli wrote:
> A few items ...
> 
> The question is missing[1] 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[2][3] 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
> settings).
> 
> footnotes/references/excerpts:
> 1. http://catb.org/~esr/faqs/smart-questions.html
> 2. http://www.unix.org/what_is_unix/single_unix_specification.html
> 3. http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
> bash(1)
> ash(1)
> sh(1)
> http://www.ecs.umass.edu/pipermail/umasslug/2008-March/date.html
> 
> > 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:
> > 
> > -mytest.sh-
> > #!/bin/bash
> > 
> > /bin/bash << EOF
> > vimdiff ~/.bashrc <(whoami)
> > EOF
> > ---
> > 
> > -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
> > https://www.ecs.umass.edu/mailman/listinfo/umasslug

-- 
Tyler Trafford

A sect or party is an elegant incognito devised to save a man from
the vexation of thinking.
                -- Ralph Waldo Emerson, Journals, 1831




More information about the sf-lug mailing list