方法一:
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