"exec not found" when using variable in exec "exec not found" when using variable in exec shell shell

"exec not found" when using variable in exec


It is caused by shell not performing variable expansion on the left side of the redirection operator. You can use a workaround:

eval exec "${PIPE_ID}"'<>"spch2008"'

It will force the shell to do variable expansion, producing

eval exec 100'<>"spch2008"'

Then the eval built-in will feed the command to the shell, which will effectively execute

exec 100<>"spch2008"


I/O redirection doesn't allow variables to specify the file descriptors generally, not just in the context of the <> redirection.

Consider:

$ cat > errmsg                     # Create scriptecho "$@" >&2                      # Echo arguments to standard error$ chmod +x errmsg                  # Make it executable$ x=2$ ./errmsg Hi                      # Writing on standard errorHi$ ./errmsg Hi ${x}>&1              # Writing on standard errorHi 2$ ./errmsg Hi 2>&1                 # Redirect standard error to standard outputHi$ ./errmsg Hi 2>/dev/null          # Standard error to /dev/null$ ./errmsg Hi ${x}>/dev/null       # Standard output to /dev/nullHi 2$