[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Errorneously flagged undefined variable with here string red
From: |
gima+ml . help-bash |
Subject: |
[Help-bash] Errorneously flagged undefined variable with here string redirected to bash-allocated file descriptor when followed by a command? |
Date: |
Sun, 9 Dec 2018 13:06:32 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 |
Hello,
I've encountered an error where bash says that a variable is undefined
when I'm accessing it, even though to my understanding it's supposed to
be defined at that point. I'm asking if I'm misunderstanding something,
or should this be treated as a bug.
I'm using the GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu),
and regarding this problem, the following relevant features:
* set -o nounset /(accessing unset variables causes error)/
* here strings redirection
* bash-allocated file descriptor from redirection, whose number is
stored to a variable
* command execution with the variable as an argument
Below are examples that demonstrate the error.
Common input file for both of the examples below:
-- showarg.sh --
#!/usr/bin/bash
set -vuex -o pipefail
echo ${@@A} ## SHOW ARGUMENTS
cat "$1" ## DISPLAY GIVEN FILE'S CONTENT
Example code that DOESN'T work:
Input:
-- test.sh --
#!/usr/bin/bash
set -vuex -o pipefail
## CREATE FILE DESCRIPTOR FROM GIVEN STRING
## AND CALL SCRIPT THAT DISPLAYS THE CONTENT OF A GIVEN FILE
{FD}<<<'hello' \
./showarg.sh "/dev/fd/$FD"
Output:
$ ./test.sh
## CREATE FILE DESCRIPTOR FROM GIVEN STRING
## AND CALL SCRIPT THAT DISPLAYS THE CONTENT OF A GIVEN FILE
{FD}<<<'hello' \
./showarg.sh "/dev/fd/$FD"
./test.sh: line 6: FD: unbound variable
To my understanding the code should work, because the following works:
555<<<'hello' ./showarg.sh "/dev/fd/555"
Example code that WORKS:
Input:
-- test2.sh --
#!/usr/bin/bash
set -vuex -o pipefail
exec {FD}<<<'hello' ## CREATE FILE DESCRIPTOR FROM GIVEN STRING
./showarg.sh "/dev/fd/$FD" ## CALL SCRIPT THAT DISPLAYS THE CONTENT OF
A GIVEN FILE
Output:
$ ./test2.sh
exec {FD}<<<'hello' ## CREATE FILE DESCRIPTOR FROM GIVEN STRING
+ exec
./showarg.sh "/dev/fd/$FD" ## CALL SCRIPT THAT DISPLAYS THE CONTENT OF
A GIVEN FILE
+ ./showarg.sh /dev/fd/10
echo ${@@A} ## SHOW ARGUMENTS
+ echo set -- ''\''/dev/fd/10'\'''
set -- '/dev/fd/10'
cat $1 ## DISPLAY GIVEN FILE'S CONTENT
+ cat /dev/fd/10
hello
- gima
- [Help-bash] Errorneously flagged undefined variable with here string redirected to bash-allocated file descriptor when followed by a command?,
gima+ml . help-bash <=