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 init
                npm init
                echo "Hé Jean, ça va ?"
                echo "J'te connais pas, ouste !"

Thanks in advance for your help !

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

Read in the input as an array:

read -p 'package name ?' -a opts

Then loop over the array:

for opt in "${opts[@]}"
    case "$opt" in
  • 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.