📄 redir.tests
字号:
: ${TMPDIR:=/tmp}export LC_ALL=Cexport LANG=C# catch-all for remaining untested redirection stuffset +o posixecho abc > /tmp/redir-testcat /tmp/redir-testset -o noclobber#this should be an errorecho def > /tmp/redir-testcat /tmp/redir-test# but this should succeedecho def > /tmp/redir-test-2cat /tmp/redir-test-2# and so should thisecho def >| /tmp/redir-testcat /tmp/redir-testset +o noclobberrm /tmp/redir-test /tmp/redir-test-2# this should be an errorz="a b"cat < $zecho "Point 1"exec 3</etc/passwdexec 4>$TMPDIR/bash-aexec 5>$TMPDIR/bash-becho "Point 2"echo to a 1>&4echo to b 1>&5cat $TMPDIR/bash-acat $TMPDIR/bash-bexec 11</dev/nullecho "Point 3"echo to a 1>&4echo to b 1>&5cat $TMPDIR/bash-acat $TMPDIR/bash-bexec 11<&-echo "Point 4"exec 6<>$TMPDIR/bash-cecho to c 1>&6cat $TMPDIR/bash-cecho "Point 5"rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c## Test the effect of input buffering on the shell's input#${THIS_SH} < redir1.sub# more open, close, duplicate file descriptors${THIS_SH} ./redir3.sub < ./redir3.in1# still more redirections${THIS_SH} ./redir4.sub < redir4.in1# various forms of null redirectiontestf(){ if [ -f "$1" ]; then rm -f "$1" else echo oops -- $1 not found fi}> $TMPDIR/null-redir-atestf $TMPDIR/null-redir-a$EXIT > $TMPDIR/null-redir-btestf $TMPDIR/null-redir-b( > $TMPDIR/null-redir-c )testf $TMPDIR/null-redir-c$EXIT > $TMPDIR/null-redir-d &waittestf $TMPDIR/null-redir-dexit 3 | $EXIT > $TMPDIR/null-redir-eecho $? -- ${PIPESTATUS[@]}testf $TMPDIR/null-redir-eexit 4 | > $TMPDIR/null-redir-fecho $? -- ${PIPESTATUS[@]}testf $TMPDIR/null-redir-f> $TMPDIR/null-redir-g &waittestf $TMPDIR/null-redir-gexec >$TMPDIR/null-redir-h &waittestf $TMPDIR/null-redir-h# make sure async commands don't get /dev/null as stdin when an explicit# input redirection is suppliedfor x in 1 2 3; do { read line ; echo $line ; } & wait { read line ; echo $line ; } & waitdone << EOFabcdefghijklEOF# make sure async commands get /dev/null as stdin in the absence of any# input redirection/bin/cat &waitecho $?# make sure that loops work OK with here documents and are not run in# subshellswhile read line; do echo $line l2=$linedone << EOFabcdEOFecho $l2# These should not echo anything -- bug in versions before 2.04( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 | cat# in posix mode, non-interactive shells are not allowed to perform# filename expansion on input redirections, even if they expand to# a single filenameset -o posixcat < redir1.*# test ksh93 dup-and-close (move fd) redirections${THIS_SH} ./redir5.sub# test behavior after a write error with a builtin command${THIS_SH} ./redir6.sub# problem with redirections using fds bash uses internally: ${TMPDIR:=$TMPDIR}trap 'rm -f $TMPDIR/bash-redir-$$' 0 1 2 3 6 15echo before block{ echo before redir exec 10>&1 echo after redir} > $TMPDIR/bash-redir-$$echo after block${THIS_SH} ./redir7.sub${THIS_SH} ./redir8.subexec 9>&2command exec 2>$TMPDIR/foo-$$echo whatsis >&2echo cat /tmp/foocat $TMPDIR/foo-$$rm -f $TMPDIR/foo-$$exec 2>&9exec 9>&-${THIS_SH} ./redir9.sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -