1

This is my bash file

#!/bin/sh
ENV=DEV
echo "env: $ENV"
if [[ "$ENV" == DEV* ]]; then
    RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
    echo "cp: $RUNTIME_CLASSPATH"
fi
echo "done"

And here's the terminal output:

~proj/bin$ ./test.sh 
env: DEV
./test.sh: 7: [[: not found
done

I don't understand what's wrong. Is there some other way of doing string comparisons?

Kevin
  • 1,080
  • 3
  • 15
  • 41

2 Answers2

5

If you want to write a bash script, then don't write a POSIX shell script: change your shebang line to:

#!/bin/bash

On the other hand, if you want to write a portable shell script, use the case statement:

case "$ENV" in 
  DEV*)
    RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
    echo "cp: $RUNTIME_CLASSPATH"
    ;;
esac
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
-1

Change

if [[ "$ENV" == DEV* ]]; then

to

if [ "$ENV" == "DEV" ]; then

.

nullshow
  • 19
  • 2
  • While this code snippet may solve the question, including an explanation of *how* and *why* this solves the problem [would really help](//meta.stackexchange.com/q/114762) to improve the quality of your post. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jan 27 '17 at 13:44