English 中文(简体)
Redirection to a strange file descriptor no
原标题:
  • 时间:2009-11-10 11:47:53
  •  标签:
  • ksh

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

最佳回答

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

问题回答

暂无回答




相关问题
How can I flush the input buffer in an expect script?

I m writing an Expect script and am having trouble dealing with the shell prompt (on Linux). My Expect script spawns rlogin and the remote system is using ksh. The prompt on the remote system contains ...

changing to parent directory in unix

in general we use cd .. for going to the parent directory cd ../../ to go to the parents parent directory. and cd ../../../../../ for 5th parent directory. is there any simplified way of doing ...

$$ in KornShell

What is the meaning of $$ in KornShell? I guess it is associated with the process ID, but I want to know its exact meaning.

vi editor query

I use vi quite often to edit files. Usually I need the file to appear on screen with line numbers. For this I do set nu in edit mode. What a drag! Can I automate this? Is there any way where vi will ...

KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

KornShell Printf - Padding a string

I m attempting to write a KornShell (ksh) function that uses printf to pad a string to a certain width. Examples: Call padSpaces Hello 10 Output Hello I currently have: padSpaces(){ ...

Redirection to a strange file descriptor no

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 ...

热门标签