This:
set -x
rm -f p; mkfifo p
exec 99<>p
succeeds in bash but fails ("99 not found"
) in dash.
How do I get it to work in dash?
The POSIX standard that was derived from the Bourne Shell and it's descendant ksh88 explicitly mentions that this is not granted to work. The reason is the shell syntax:
<>file
opens stdin for reading and writing, and:
[n]<>file
opens file descriptor n
for reading and writing.
n
in this case is a single digit.
You used the number 99 and this is a two digit number that is outside the range specified by POSIX. So the parser did not see it as a number that is related to the redirection operator but as a separate argument. So this argument was seen as the file to execute by exec
.
If you like portable scripts, follow the POSIX standard and if you like to write fully portable scripts, make things 100% Bourne Shell compatible.
As there does not seem to be a reason for using 99 in your case, I recommend to use 9.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments