Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I just tested the following syntax on Linux:

case "$OSTYPE" in linux-gnu*) ;;& linux*) echo $OSTYPE; ;; esac
case "$OSTYPE" in linux-gnu*) ;& linux*) echo $OSTYPE; ;; esac

which works without any problems (See: Can bash case statements cascade?) with GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu).

But on OSX I've the following errors:

-bash: syntax error near unexpected token `&'
-bash: syntax error near unexpected token `;'

It's GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13).

Any clues how to achieve the same fall-through behavior on bash v3?

share|improve this question
    
Is your code in the first lines just a sample or the real code you want to run? –  patrix Aug 12 at 10:55
    
It's ready copy&paste code to run. The real script is .bashrc at lines 58-59 which are commented out, because they doesn't work on OSX. –  kenorb Aug 12 at 11:08

1 Answer 1

Either upgrade your bash (homebrew) or you'll have to recode it using a series of if statements:

case "$OSTYPE" in linux-gnu*) ;;& linux*) echo $OSTYPE; ;; esac
case "$OSTYPE" in linux-gnu*) ;& linux*) echo $OSTYPE; ;; esac

would be

# first case
if [[ $OSTYPE == linux-gnu* ]]; then
    : # nothing in this branch
fi 
if [[ $OSTYPE == linux* ]]; then
    echo $OSTYPE
fi

# second case
function print_ostype { echo $OSTYPE; }
if [[ $OSTYPE == linux-gnu* ]]; then
    # nothing in this branch
    # include the next branch
    print_ostype
elif [[ $OSTYPE == linux* ]]; then
    print_ostype
fi

I used a function in the 2nd case to reduce code duplication, in case there's multiple statements.

share|improve this answer
    
you should to use the : for the empty branch... the pure # ... throws error ;) –  jm666 Aug 12 at 12:28
    
Thanks, good catch. –  glenn jackman Aug 12 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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