I read Can a Bash script tell what directory it's stored in?, it shows I can get script directory by DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
.
I find I can use cd
command to change working directory.
This is the content of import.sh. It is in /Users/gqqnbig/SourceCode/Java/PlayerStatisticReader/bin
.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd DIR
java -cp .;jsoup-1.7.3.jar;mysql-connector-java-5.1.29-bin.jar globalVisionEntertainment.nba.Program %1
This is what I get after executing the script.
Macintosh:PlayerStatisticReader gqqnbig$ pwd
/Users/gqqnbig/SourceCode/Java/PlayerStatisticReader
Macintosh:PlayerStatisticReader gqqnbig$ bin/import.sh
: command not found 2:
: No such file or directoryDIR
: command not found 4:
I execute it in the default terminal in Macintosh.
Why is the command not found? How can I make it work?