tags:

views:

30

answers:

1

I came across a working ksh script [interactive] today, where I saw the below statement.

printf "Enter the release no. : " >&5

I wonder the use of ">&5" when the author could have as well use nothing or say ">&1".

Can someone shed some light on this point?

Thanks in advance

-- Benil

+3  A: 

He probably has remapped the file descriptors or does use the file descriptor 5 for something special

e.g. to only temporarily redirect errors to /dev/null

#errors produced here go to stderr
....
#now save stderr to fd 5
exec 5>&2
#redirect to /dev/null
exec 2>/dev/null
...
# do stuff which errors are discarded
......
# restore stderr from fd 5
exec 2>&5

So check more of the script what it does before

jitter
+1 for a helpful, real-world example. Redirecting file descriptors is one of those features that can perform magic if you take the time to learn the nuances.
Adam Liss
Jitter, you are right. The author has defined it earlier and he mapped stdout to descriptor 5 first and then to a log file. That way standard cmds' o/p will go to logfiles and occasionally to print something on screen he used desc.5 Thanks a lot. --Benil
Ben
No problem. Then accept answer
jitter

related questions