我有以下代码,其中我的if
条件在简单的shell脚本中不起作用。
#!/bin/sh
run() {
cd /tmp/in/current; java -Dlog4j.configurationFile=/tmp/in/logging/log4j2_Importer.xml -Djava.security.egd=file:///dev/urandom -classpath /tmp/in/betl-runner/lib/*:/tmp/in/lib/* baag.betl.runner.Application --config /tmp/in/config/import.dev.properties.TODO --workflow import --inputDir "$1"
}
dev_path="/tmp/in"
mode=$1
if [ "$mode" = "$dev_path" ]; then
run "$mode"
fi
在if
条件下,如果我只是执行if [ "$mode" = "" ];
,则代码会以某种方式运行,但我不知道为什么以上if
条件会失败。
在脚本中,将mode
的值设置为$1
,这是脚本的第一个参数。尝试像这样调用它:
$ myscript /tmp/in
其中myscript
是您的ShellScript文件的名称。
您应该通过向其传递一个参数来运行代码,因为OP在注释中确认没有传递任何参数,所以如果条件失败,则返回代码。
运行方式(这里只是一个例子):
./script.sh "/tmp/in"
script.sh
是您的Shell脚本代码。