When I try to run the command below in Ubuntu:

sudo -n -u contd sh --login -c ". /home/contd/iib-;/home/contd/iib- -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- -Dant.home=/usr/share/ant org.apache.tools.ant.Main -f /home/contd/AntScript/build_main.xml"

I get this error:

sh: 0: Illegal option --

The above command is supposed to be supported in Linux, but when I try to implement the same solution (Ant scripting) in Ubuntu, I face this problem.

  • 5
    I don't think the dash shell supports a long-form --login option: see DashAsBinSh Nov 27 '16 at 18:54
  • 3
    A quick fix would be to replace --login with just -l.
    – Seth
    Nov 27 '16 at 18:59

sh on ubuntu is a symlink to the dash shell, not bash. Dash does not support the longform --login, but it does support the shorthand form, -l (from man dash):

-l Make dash act as if it had been invoked as a login shell.

Replacing --login with -l in your command should fix your issue.

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

If you want to invoke bash instead of dash simply call bash instead of sh.

sudo -n -u contd bash --login -c ". <etc>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.