0

I am looking to create an interactive bash script for our development team (never did this before) as our project has various needs and due to future growth on the team I want this to be easy as pi.

Normally for my work on the team I would change directory to the angular folder and run ng serve which kicks off the frontend development server. How do I do that in a bash script?

So far I have this:

#!/bin/bash
echo -e "Hello, "$USER".\nWelcome to the BICE build script!\nVersion 0.1"
echo -e "Which build option do you wish to use?\n1. Frontend (default)\n2. Backend\n3. Database\n4. Production"
echo -n "Enter your choice [1-4] or press [ENTER]:"
read choice
if [choice == 1]; then
  echo "Option 1 selected"
  cd /angular
  #call ng serve

Thanks!

Kim Kern
  • 54,283
  • 17
  • 197
  • 195
Lance
  • 61
  • 1
  • 8

1 Answers1

4

/angular seems weird as a working directory but if angular is a subdirectory of the one holding the script a

cd ./angular
ng serve
cd ..

should work...

Maybe you could look at this question so you can call the script from any working directory.

Also note that you are missing a fi at the end of your if, there sould be spaces after opening and before closing bracket and choice should be referenced with a $ sign:

#!/bin/bash
echo -e "Hello, "$USER".\nWelcome to the BICE build script!\nVersion 0.1"
echo -e "Which build option do you wish to use?\n1. Frontend (default)\n2. Backend\n3. Database\n4. Production"
echo -n "Enter your choice [1-4] or press [ENTER]:"
read choice
if [ $choice == 1 ]; then
  echo "Option 1 selected"
  cd ./angular
  ng serve
  cd ..
fi
Community
  • 1
  • 1
n00dl3
  • 21,213
  • 7
  • 66
  • 76
  • When I do the above (my first thoughts too) I get syntax error: unexpected end of file. That got me thinking that it tried but couldn't so reached EOF and died. – Lance Mar 29 '17 at 14:34
  • This is so cool! Thanks for the help I can probably muddle my way through now and using the documentation. – Lance Mar 29 '17 at 14:46