bug-bash
[Top][All Lists]
Advanced

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

Re: bash 2.05b has a problem with command substitution that bash2.03.0(1


From: Chet Ramey
Subject: Re: bash 2.05b has a problem with command substitution that bash2.03.0(1) doesn't have.
Date: Thu, 12 Jun 2003 16:27:53 -0400

> Machine Type: i686-pc-linux-gnu
> 
> Bash Version: 2.05b
> Patch Level: 0
> Release Status: release
> 
> Description:
>     A ksh script that I have used for years with AIX, HP-UX, IRIX and Sun=
> OS
>     contains the following command for obtaining the pid of the interacti=
> ve login shell
>     executing the command:
> 
>     LOGIN_PID=3D$(who -u | grep " `who am I | sed 's/^ *[^ ]* *\([^ ]*\).=
> *$/\1/'` " | tr "\011" ' ' | tr -s " " | cut -d' ' -f7)
> 
>     Under SunOS 5.8 Generic_108528-19 sun4u sparc SUNW,Ultra-Enterprise
>     with GNU bash, version 2.03.0(1)-release (sparc-sun-solaris) [obtaine=
> d with: bash --version]
>     this command also works.
> 
>     With bash 2.05b under Linux 2.4.18-14 this command doesn't work as ex=
> pected.
>     I have to split it up as follows to get the desired result:
> 
>     LINE=3D" `who am I | sed 's/^ *[^ ]* *\([^ ]*\).*$/\1/'` "
>     LOGIN_PID=3D$(who -u | grep "$LINE" | tr "\011" ' ' | tr -s " " | cut=
>  -d' ' -f7)

This is not a bash bug.  It's a difference between Linux and the other
versions of Unix.  When you run the command substitution in a pipeline,
the process has no controlling terminal, and `who am I' returns nothing.

You can see that for yourself by running

echo | who am I

in any shell of your choosing.  When you split the command and assign
`LINE', the process has a controlling terminal, and `who am I' returns its
path.

Your command works as expected with bash-2.05b on Solaris 7.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )

Chet Ramey, ITS, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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