redir1.sh
来自「Shall高级编程」· Shell 代码 · 共 36 行
SH
36 行
#!/bin/bash# Redirecting stdin using 'exec'.exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin.exec < data-file # stdin replaced by file "data-file"read a1 # Reads first line of file "data-file".read a2 # Reads second line of file "data-file."echoecho "Following lines read from file."echo "-------------------------------"echo $a1echo $a2echo; echo; echoexec 0<&6 6<&-# Now restore stdin from fd #6, where it had been saved,#+ and close fd #6 ( 6<&- ) to free it for other processes to use.## <&6 6<&- also works.echo -n "Enter data "read b1 # Now "read" functions as expected, reading from normal stdin.echo "Input read from stdin."echo "----------------------"echo "b1 = $b1"echoexit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?