-1

Is it possible for a shell script to prompt a user of where to create a directory?

echo -n "Enter folder path location::::"
jquerynoob
  • 663
  • 1
  • 7
  • 15
  • possible duplicate of [How do I prompt for input in a Linux shell script?](http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script) – Ross Ridge Sep 01 '14 at 19:46

4 Answers4

1
echo -n 'Enter folder path location: '
read folder_path
echo "You entered $folder_path"
Mark Reed
  • 91,912
  • 16
  • 138
  • 175
1
echo -n "Enter folder path location::::"
read folderName
echo "$folderName is the directory name inserted"

You can add many controls. I think it's better that you start reading some bash manual and books. Something like Advanced BASH Scripting Guide.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • I disagree with the suggestion to read the Advanced BASH Scripting Guide, but I don't see anything in this answer that merits a downvote. – chepner Aug 31 '14 at 18:55
1

You can use the prompt feature of the read, like:

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
clt60
  • 62,119
  • 17
  • 107
  • 194
1

Try this:

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
ice13berg
  • 713
  • 8
  • 12