- 论坛徽章:
- 84
|
注意:管道后的命令是在subshell中执行的
- #!/bin/sh
- # readpipe.sh
- # This example contributed by BjonEriksson.
- OIFS=$IFS; IFS=
- last="(null)"
- cat $0 |
- while read -r line
- do
- echo "{$line}"
- last=$line
- done
- printf "\nAll done, last:$last\n\n"
- exit 0 # End of code.
- # (Partial) output of script follows.
- # The 'echo' supplies extra brackets.
- IFS=$OFS
- #############################################
复制代码[root@142 work]# sh kkk1.sh
{#!/bin/sh}
{#readpipe.sh}
{#This example contributed by BjonEriksson.}
{OIFS=$IFS; IFS=}
{}
{last="(null)"}
{cat $0 |}
{while read -r line}
{do}
{ echo "{$line}"}
{ last=$line}
{done}
{printf "\nAll done, lastlast\n\n"}
{}
{exit 0 # End of code.}
{ # (Partial) output of script follows.}
{ # The 'echo' supplies extra brackets.}
{IFS=$OFS}
{#############################################}
All done, lastnull)
[root@142 work]#
The variable (last) is set within the subshell but unset outside.
[ 本帖最后由 yjh777 于 2006-6-7 17:21 编辑 ] |
|