您的位置:首页 > 运维架构 > Shell

shell实践(一)读取一个文件输出文件内容

2015-10-21 10:29 489 查看
方法一:

vi s.sh

#!/bin/bash

if test -e "$1" #第一个参数是否为文件

then

    cat $1 | while read line

    do

        echo $line

    done

fi

:wq

chmod +x s.sh

./s.sh file

方法二:

#!/bin/bash

if [ -f "$1" ];then

    while read line

    do

        echo $line

    done < $1

else

    echo "文件不存在"

fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell