problems with a subshell in .profile

View: New views
2 Messages — Rating Filter:   Alert me  

problems with a subshell in .profile

by Nils-20 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I use a shared .profile for bash and ksh93, I have a ksh93 specific
section which I want to separate through the following construct:

if ( test -n "${.sh.version}" ) 2>/dev/null; then
    echo "ksh"
fi

bash just hangs while it works in POSIX shell and ksh93. A bash script
with above contents also works as expected.
Why is this?

Re: problems with a subshell in .profile

by Chet Ramey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nils wrote:

> I use a shared .profile for bash and ksh93, I have a ksh93 specific
> section which I want to separate through the following construct:
>
> if ( test -n "${.sh.version}" ) 2>/dev/null; then
>     echo "ksh"
> fi
>
> bash just hangs while it works in POSIX shell and ksh93. A bash script
> with above contents also works as expected.
> Why is this?

This is a bug.  The shell doesn't hang (type a command, and you'll get
output), but the bad substitution causes a longjmp back to the subshell's
top level, and it's trying to read input from the terminal.  You don't
see anything because that shell's stdout is redirected to /dev/null.
This will be fixed in bash-4.1.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@...    http://cnswww.cns.cwru.edu/~chet/