linux shell经典应用

Life is short , play more!
本文来自lihao's Blog,转载请注明。

1. 执行某文件

cat /tmp/cli | while read command ; do
{
if [ ! -z “$command” ] ; then
echo “===============================================” | tee -a $logs
echo “===============================================” >> $results
echo -e “case:  $command \n” >> $logs
eval $command >> $logs 2>&1
if [ x$? == “x0” ]; then
echo “$command pass” |tee -a $results
else
echo “$command fail” |tee -a $results
echo “$command fail” >> $error_logs
fi
fi
}

2. 文件描述符操作
exec 6>&1
exec 1>/tmp/hello
echo hello
exec 1>&-
exec 1>&6
exec 6>&-
3. 文件操作

cat > /tmp/hello << eof
hello , everybody
eof


发表评论

电子邮件地址不会被公开。 必填项已用*标注