[lug] Subshell behavior with potato bash?

Aaron Crane aaron.crane at pobox.com
Thu Jan 20 11:27:38 MST 2000


socket at peakpeak.com writes:
> Since I upgraded to debian potato a month ago or so, an upgrade of
> bash (or perhaps grep) started breaking a declaration in my
> .bash_profile.
> 
> Here's the relevant line:
> 
> f="$(who | grep $(tty | sed s./dev/..))"

Hi, Chris.  This is actually my fault.  The problem is that when tty has its
input connected to a file descriptor which isn't a tty, it says "not a tty"
-- which is perfectly true.  This output is then split up and put into
arguments for grep, which will then look for "not" in the files "a" and
"tty".  Since these don't exist, you get error messages from grep.

I fixed this as follows:

    f=$(tty); f="$(who | grep "${f#/dev/}")"

which additionally saves a sed process.

> I can probably fix this myself if someone could explain just what a $
> before () does.  I would assume that it might be the return value of
> the subshell, when the subshell finishes, maybe the output of the
> subshell...

It's the output of the subshell -- like backticks, but with a readable
syntax.  See also <URL: http://www.deja.com/getdoc.xp?AN=512762538 >.

-- 
Aaron Crane   <aaron.crane at pobox.com>   <URL:http://pobox.com/~aaronc/>




More information about the LUG mailing list