shell编程连载【1】-创建归档文件

(1) vi  bundle.sh


(2)

hello1

hello2

 

(3) 执行sh boudle.sh h1.txt h2.txt >bakfiles

(4)


(5) 执行 bash bakfiles可恢复h1.txt,h2.txt

 

 【解析】

(1)为什么执行bash bakfiles可恢复h1.txt,h2.txt?

      先来看一下bakfiles的内容,执行cat bakfiles

# To unbundle, bash this file
echo h1.txt 1>&2
cat >h1.txt <<'End of h1.txt'
hello1
hello2

End of h1.txt
echo h2.txt 1>&2
cat >h2.txt <<'End of h2.txt'
hello3
End of h2.txt
原来在执行sh boudle.sh h1.txt h2.txt >bakfiles后,bakfiles中生成了2条文件重定向语句:

cat >h1.txt <<'End of h1.txt'
cat >h2.txt <<'End of h2.txt'
再用bash解析bakfiles也就达到了恢复文件的目的。

(2) 1>&2的涵义

0:标准输入

1:标准输出

2:标准错误

>&:可复制的文件描述符

1>&2即是将标准输出重定向为标准错误。

 

 

posted @ 2011-09-27 10:25  j2ee技术  阅读(192)  评论(0编辑  收藏  举报