[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Assigning to BASHPID fails silently
From: |
Martijn Dekker |
Subject: |
Assigning to BASHPID fails silently |
Date: |
Mon, 17 Oct 2016 20:38:29 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
bash 4.4.0 (I did not investigate other versions) does not produce an
error message if you try to assign something to the BASHPID readonly
using either arithmetic or normal assignment. Other readonlies produce a
message on an assignment attempt. BASHPID seems to be an exception.
<background type="superfluous">
Particularly annoying is that a non-interactive shell will exit silently
on a mistaken attempt to assign to BASHPID. I was making a bash function
to determine if we're in a subshell. Because of the lack of error
message, it took some doing to find my typo in
return "$((BASHPID = $$))"
(of course, comparison is '==' and not '='). Not even 'set -x' will give
a clue; it exits before producing relevant tracing output.
</background>
Proof below. (The exit status of the previous command is included in the
prompt in the output below.)
[0]$ UID=0
bash: UID: readonly variable
[1]$ BASHPID=0
[1]$ ((UID=0))
bash: UID: readonly variable
[1]$ ((BASHPID=0))
[1]$
Thanks,
- Martijn
- Assigning to BASHPID fails silently,
Martijn Dekker <=
- Re: Assigning to BASHPID fails silently, Eduardo A . Bustamante López, 2016/10/18
- Re: Assigning to BASHPID fails silently, Chet Ramey, 2016/10/19
- Re: Assigning to BASHPID fails silently, Martijn Dekker, 2016/10/19
- Re: Assigning to BASHPID fails silently, Greg Wooledge, 2016/10/20
- Re: Assigning to BASHPID fails silently, Martijn Dekker, 2016/10/20
- Re: Assigning to BASHPID fails silently, lolilolicon, 2016/10/20
- Re: Assigning to BASHPID fails silently, lolilolicon, 2016/10/20