I have a certain bash script, which wants to preserve original
/dev/stdout location before replacing 1st file descriptor with other location.
So, naturally, I wrote something like
old_stdout=$(readlink -f /dev/stdout)
And it didn't work. Very quickly I understand what the problem was:
[email protected]:~$ echo $(readlink -f /dev/stdout) /proc/5175/fd/pipe: [email protected]:~$ readlink -f /dev/stdout /dev/pts/18
$() runs in a subshell, which is piped to the parent shell.
So the question is: is there a reliable (scoped to portability between Linux distributions) way to save
/dev/stdout location as a string in a bash script?