sh:0:非法选项-


10

当我尝试在Ubuntu中运行以下命令时:

sudo -n -u contd sh --login -c ". /home/contd/iib-10.0.0.5/server/bin/mqsiprofile;/home/contd/iib-10.0.0.5/common/jdk/jre/bin/java -cp $CLASSPATH:$MQSI_JREPATH//usr/share/ant/lib/ant-antlr.jar:/usr/share/ant/lib/ant-apache-bcel.jar:/usr/share/ant/lib/ant-apache-bsf.jar:/usr/share/ant/lib/ant-apache-log4j.jar:/usr/share/ant/lib/ant-apache-oro.jar:/usr/share/ant/lib/ant-apache-regexp.jar:/usr/share/ant/lib/ant-apache-resolver.jar:/usr/share/ant/lib/ant-apache-xalan2.jar:/usr/share/ant/lib/ant-commons-logging.jar:/usr/share/ant/lib/ant-commons-net.jar:/usr/share/ant/lib/ant-javamail.jar:/usr/share/ant/lib/ant-jdepend.jar:/usr/share/ant/lib/ant-jmf.jar:/usr/share/ant/lib/ant-jsch.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-swing.jar:/usr/share/ant/lib/ant-testutil.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/jsch.jar:/usr/share/ant/lib/junit.jar -Djava.ext.dirs=/home/contd/iib-10.0.0.5/common/jdk/lib:/home/contd/iib-10.0.0.5/common/jdk/jre/lib/ext -Dant.home=/usr/share/ant org.apache.tools.ant.Main -f /home/contd/AntScript/build_main.xml"

我收到此错误:

sh: 0: Illegal option --

上面的命令应该在Linux中受支持,但是当我尝试在Ubuntu中实现相同的解决方案(Ant脚本)时,我遇到了这个问题。


5
我认为dash外壳程序不支持长格式--login选项:请参阅DashAsBinSh
steeldriver

3
一个快速的解决方法是--login用just 代替-l
赛斯

Answers:


17

sh在ubuntu上,是到破折号外壳的符号链接,而不是bash。Dash不支持longform --login,但它支持简写形式-l(from man dash):

-l 使破折号的行为就好像它已作为登录外壳程序被调用一样。

在命令中替换--login-l可以解决您的问题。

sudo -n -u contd sh -l -c ". <etc>

如果要调用bash而不是破折号,只需调用bash而不是即可sh

sudo -n -u contd bash --login -c ". <etc>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.