0

I get an error (on line: sh up.sh) running the following:

#!/bin/bash

# Install angular components 
echo "Installing Angular Components..."
cd angApp
npm install

# Install Server components
echo "Installing Backend Components..."
cd ..
cd APIServer

# go back to main dir
cd ..

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

How do I run the up.sh script?

3
  • What error do you get? Commented Feb 28, 2015 at 19:58
  • up.sh: No such file or directory Commented Feb 28, 2015 at 19:59
  • 1
    You've done some cding. Run a pwd or echo $PWD to check you're in the right directory when you try to run up.sh. Commented Feb 28, 2015 at 20:03

2 Answers 2

2

If the up.sh file is in the same directory as the file containing the code above then you can do

echo "Great! Launching the servers for you..."
$(dirname $0)/up.sh

The variable $0 is the path of the current script, dirname strips off the last segment of the path, and $(...) turns the output of dirname into a string.

Sign up to request clarification or add additional context in comments.

Comments

1

To avoid cd-ing mess, simply run the parts in subshells, like:

#!/bin/bash

(
# Install angular components - in shubshell
echo "Installing Angular Components..."
cd angApp
npm install
)

(
# Install Server components - again in subshell
echo "Installing Backend Components..."
cd APIServer
#do something here
)    

# go back to main dir
#cd .. #not needed, you're now in the parent shell...

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.