shell脚本是否可以提示用户在何处创建目录?
echo -n "Enter folder path location::::"
答案 0 :(得分:1)
echo -n 'Enter folder path location: '
read folder_path
echo "You entered $folder_path"
答案 1 :(得分:1)
echo -n "Enter folder path location::::"
read folderName
echo "$folderName is the directory name inserted"
您可以添加许多控件。 我认为你开始阅读一些bash手册和书籍会更好。像Advanced BASH Scripting Guide.
这样的东西答案 2 :(得分:1)
您可以使用阅读的提示功能,例如:
err() {
echo "Error: $@" >&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
答案 3 :(得分: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