【发布时间】:2017-04-06 01:49:35
【问题描述】:
我试图错误捕获用户输入。
-我需要用户输入文件名。
-一些用户正在输入完整的 url,这会杀死脚本的其余部分。
- 所以如果用户输入 http:// 我希望脚本给出错误消息并让他们只输入文件名。
-每次用户输入url时都需要重复。
- 如果他们输入文件名,那么脚本的其余部分就会执行。
这是我到目前为止所拥有的。如果用户输入 url 一旦它工作,但如果他输入错误两次,它将执行脚本的其余部分
#!/bin/bash
read -p "Enter File : " string
if [[ $string -ne *”http://“* ]];
then
s3cmd get s3://backup/domain.com/$string
elif [[ $string -ne *"http://"* ]];
echo “You entered the full URL, enter on the file name“
read -p "Enter File : " string
then
s3cmd get s3://backup/domain.com/$string
else
echo "rest of script"
fi
【问题讨论】:
标签: bash loops error-handling