"exec not found" when using a variable in exec
2 answers
This is because the shell does not perform variable expansion on the left side of the redirection operator. You can use a workaround:
eval exec "${PIPE_ID}"'<>"spch2008"'
This will force the shell to execute variable expansion by creating
eval exec 100'<>"spch2008"'
The inline eval
will then feed a command to the shell that will efficiently execute
exec 100<>"spch2008"
+3
source to share
I / O redirection prevents variables from specifying file descriptors, usually outside of the redirection context <>
.
Consider:
$ cat > errmsg # Create script
echo "$@" >&2 # Echo arguments to standard error
$ chmod +x errmsg # Make it executable
$ x=2
$ ./errmsg Hi # Writing on standard error
Hi
$ ./errmsg Hi ${x}>&1 # Writing on standard error
Hi 2
$ ./errmsg Hi 2>&1 # Redirect standard error to standard output
Hi
$ ./errmsg Hi 2>/dev/null # Standard error to /dev/null
$ ./errmsg Hi ${x}>/dev/null # Standard output to /dev/null
Hi 2
$
0
source to share