[Bash]Linux Bash脚本命令等待、获取用户的输入

2021-01-09 1009点热度 0人点赞 0条评论

编写Linux脚本的时候,有时需要等待用户输入变量,然后根据变量不同来执行接下来的操作,

举例如下:

#!/bin/sh

echo -n "Enter file name and press [ENTER]: "
read file_name
echo "file name is: $file_name"

if [ -z "$file_name" ]; then
    echo 'empty file name, exit'
else
    #执行接下来的操作
    #...
fi

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论