0

I have a bash program with different stages like:

$stage=1

if [ stage -le 1]; then echo "execute stage 1" fi
if [ stage -le 2]; then echo "execute stage 2" fi
if [ stage -le 3]; then echo "execute stage 3" fi

my codes in stages are very computationally expensive. What I want is to execute those stages which are required.

How can I call stage 3 directly and skip stage 1 and stage 2 from command terminal in linux.

Thanks

  • 1
    Change -le to -eq? BTW you need whitespace before the closing ]s – steeldriver Jan 15 '17 at 18:12
  • And how to call this script with stage 3: like the name of the script is stages.sh ? – ASAD Jan 15 '17 at 18:34
1

You could probably use a case statement for this one. Let's say we create a script called stage.sh, then it could be something like this:

#!/bin/bash
case $1 in
        1) echo "stage 1" ;;
        2) echo "stage 2" ;;
        3) echo "stage 3" ;;
        *) echo "unknown stage" ;;
esac

What it does is that it takes the first input ($1) when called from the command line and matches it with the case statement. Here, running ./stage.sh 1 would display stage 1, and ./stage.sh 5 would display unknown stage since there is no case match (so it will resort to the *) option).

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.