-1
A
回答
1
试试这个:
while read -ep "Enter folder path location: " file_dir; do
if [ -d "${file_dir}" ]; then
echo "${file_dir} already exists - please enter a valid directory path."
else
mkdir -p "${file_dir}"
break
fi
done
的[我如何在Linux提示输入
+0
感谢这很好,我正在寻找。 – jquerynoob 2014-09-05 21:41:57
1
echo -n 'Enter folder path location: '
read folder_path
echo "You entered $folder_path"
1
echo -n "Enter folder path location::::"
read folderName
echo "$folderName is the directory name inserted"
您可以添加许多控件。 我认为你最好开始阅读一些bash手册和书籍。像Advanced BASH Scripting Guide.
+0
我不同意阅读高级BASH的建议脚本指南,但我没有看到这个答案中有什么值得的downvote。 – chepner 2014-08-31 18:55:43
1
东西,你可以使用读取的提示功能,如:
err() {
echo "Error: [email protected]" >&2 ; return 1
}
while :
do
read -r -p "Enter directory name > " newdir
#check already exists
[[ ! -e "$newdir" ]] || err "$newdir exists" || continue
#if want to find real parent directory
#real="$(cd "$(dirname "$newdir")" && /bin/pwd -P)" || continue
#some other safety tests here if need
#create a directory, if success - break the cycle
mkdir "$newdir" && break
#otherwire repeat the question...
done
#ok
相关问题
- 1. 如何从文本文件中向交互式bash脚本提供输入
- 2. bash脚本来重命名文件夹
- 3. bash脚本复制无名文件夹
- 4. Bash shell脚本提示用户输入(CLI GUI)对话框
- 5. bash脚本shell输入
- 6. 用于输入和输出文件夹位置的配置文件
- 7. MATLAB:将当前文件夹设置为脚本的位置
- 8. bash脚本:提取和转换文件
- 9. 使用bash脚本将多个输入文字写入文本
- 10. BASH:插入文本在特定位置
- 11. 确定文件位置是否是bash脚本中的别名
- 12. 快速bash脚本在指定文件夹中运行脚本?
- 13. Bash Shell脚本遍历文件夹内的文件夹和复制文件
- 14. 如何提示输入脚本?
- 15. PowerShell v1脚本提示输入密码
- 16. perl bash脚本输出输入
- 17. 终端提示基本bash脚本
- 18. 使用函数设置脚本文件夹位置失败
- 19. 将输出的bash脚本写入日期文件
- 20. 将bash脚本输出的多个文件导入Python列表
- 21. 对不同文件夹中的文件执行bash脚本
- 22. 将文件分类到同名文件夹的Bash脚本
- 23. Bash脚本遍历文件夹树并从捆绑中提取文件
- 24. 从csv文件读入bash脚本
- 25. 在bash脚本中指定输入文件
- 26. Bash文件脚本转义用户输入
- 27. Bash脚本在给定文件夹中查找文件类型
- 28. Bash脚本根据文件大小更改移动文件夹?
- 29. bash脚本创建文件夹和移动文件
- 30. 创建一个文件,并把它放入文件夹 - bash脚本
可能重复shell脚本?](http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script) – 2014-09-01 19:46:34