0

I am a beginner at shell scripts, and i am trying to create a basic script that creates starter environnements for web projects.

I would like to tell my case loop, to read all arguments passed to read -p 'package name ?' and if one of them equal to case option execute that option. For example, if i write 'package name' npm git, do npm init and git init.

read -p 'folder name ?' nom
mkdir /Users/ineszarka/Sites/$nom
cd /Users/ineszarka/Sites/$nom
read -p 'package name ?' opt optt
case $opt OR $optt  in
        "git")
                git init
                ;;
        "npm")
                npm init
                ;;
        "Jean")
                echo "Hé Jean, ça va ?"
                ;;
        "quit")
                break
                ;;
        *)
                echo "J'te connais pas, ouste !"
                ;;
esac

Thanks in advance for your help !

1
  • You might like to use shellcheck.net as part of your learning process – roaima Oct 16 '19 at 8:36
1

Read in the input as an array:

read -p 'package name ?' -a opts

Then loop over the array:

for opt in "${opts[@]}"
do
    case "$opt" in
    ...
    esac
done
1
  • Yes that's it thank you ! – Inès Zarka Oct 16 '19 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.