Linux shell命令之脚本的灵活性
作者:互联网
一个不灵活的脚本的例子
#!/bin/bash
#判断已知目录下的指定文件是否存在
if [ -f /home/wyq/shell/file_can_execute_or_not2.sh ]
then
echo "Able to find The file /home/wyq/shell/file_can_execute_or_not2.sh"
elif [ -f /home/wyq/shell/chapter15/file_can_execute_or_not2.sh ]
then
echo "Able to find the file /home/wyq/shell/chapter15/file_can_execute_or_not2.sh! "
else
echo "Unable to find the file file_can_execute_or_not2.sh !"
fi
./file_exist_or_not1.sh
Unable to find the file file_can_execute_or_not2.sh !
一个灵活的脚本的例子
vi file_exist_or_not2.sh
#!/bin/bash
#提示用户输入目录名
echo "Please input the directory name:"
read dname
#判断第一个输入的参数是否为目录名
if [ ! -d $dname ]
then
echo "unable to read or find the director $dname"
fi
#提示用户输入文件名
echo "Please input the filename: "
read fname
#判断文件是否存在
if [ -f "$dname/$fname" ]
then
echo "Aable to find the file $dname/$fname"
else
echo "Unable find the file $dname/$fname"
fi
./file_exist_or_not2.sh
Please input the directory name:
/home/aloy
Please input the filename:
file_can_execute_or_not2.sh
Aable to find the file /home/aloy/file_can_execute_or_not2.sh
标签:execute,shell,not2,灵活性,echo,sh,file,Linux,find 来源: https://www.cnblogs.com/zhudaheng123/p/14652739.html