S
S
sazhyk2016-08-17 12:58:35
bash
sazhyk, 2016-08-17 12:58:35

Completion of the folder creation script?

Good afternoon. Help to finalize the folder creation script. The script should ask the user with what name to create a folder. And check before creating: if the folder exists, then you must offer to enter the folder name again, respectively, if there is no such folder, then create it and exit.
The script itself:

#!/bin/bash

PARENT_DIR=$HOME
echo "Укажите имя папки:"
read DIRNAME
...
понимаю что тут должно быть что-то такое
while true
do
  case $DIRNAME in
    $PARENT_DIR )
      echo "Папка есть. Введите другое имя"
      ;;
    mkdir $DIRNAME
  esac
done
...

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2016-08-17
@sazhyk

why such torment, just do it:

echo "Укажите имя папки:"
read Dir
mkdir -p $Dir

if not, it will create it, if there is, it's okay, the error will be suppressed with the -p parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question