-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