Вопрос

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?

Это было полезно?

Решение

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

Другие советы

Change

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

to

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

.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top