Bash and hard-bracket tests

26 views
Skip to first unread message

Rob Mandeville

unread,
Aug 25, 2015, 9:51:38 AM8/25/15
to jenkins...@googlegroups.com, Rob Mandeville

Take the following script:

 

 

if [ foo == foo ]; then

   echo foo is foo

fi

 

if [ foo == bar ]; then

  echo foo is bar

fi

 

When I run this from the Linux command line, I get:

 

foo is foo

 

When I add “#!/bin/bash –ex” as a shebang, I get the expected line dump plus the “foo is foo” line.

 

 

When I make this an “execute shell” build step, and run that step on a linux slave, I get:

 

[bash hard bracket test] $ /bin/sh -xe /tmp/hudson942109571990858458.sh

+ [ foo == foo ]

/tmp/hudson942109571990858458.sh: 2: [: foo: unexpected operator

+ [ foo == bar ]

/tmp/hudson942109571990858458.sh: 6: [: foo: unexpected operator

 

When I add a “#!/bin/bash” to the step as a shebang, I just get the expected “foo is foo” line.  And if I add a “#!/bin/bash –ex” shebang to the step, I get the same thing that I get when running the script with the shebang from the command line.

 

In any case, whenever I run this as a build, the SHELL environment variable is “/bin/bash”

 

 

Why does running a shell step without a shebang behave differently than it does with a “#!/bin/bash –ex” shebang?  Exactly what is being run without  a shebang?

 

Thanks in advance,

 

--Rob Mandeville

Deka Research and Development



This e-mail and the information, including any attachments it contains, are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.

Dirk Heinrichs

unread,
Aug 25, 2015, 9:59:04 AM8/25/15
to jenkins...@googlegroups.com
Am 25.08.2015 um 15:51 schrieb Rob Mandeville:

Why does running a shell step without a shebang behave differently than it does with a “#!/bin/bash –ex” shebang?  Exactly what is being run without  a shebang?

What sh is, depends on your OS. It may be bash, or something else.

CentOS:
# ll =sh
lrwxrwxrwx. 1 root root 4 Nov 18  2014 /bin/sh -> bash

Ubuntu:
# ll =sh
lrwxrwxrwx 1 root root 4 Dec  2  2014 /bin/sh -> dash

HTH...

    Dirk
--

Dirk Heinrichs, Senior Systems Engineer, Engineering Solutions
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Tel: +49 2226 1596666 (Ansage) 1149
Email: d...@recommind.com
Skype: dirk.heinrichs.recommind
www.recommind.com

Rob Mandeville

unread,
Aug 25, 2015, 10:11:36 AM8/25/15
to jenkins...@googlegroups.com, Rob Mandeville

I’m using Ubuntu, and have never heard of dash (though I just checked and verified that /bin/sh is a symlink to it).  Are you saying that, if no shebang is given, the build step ignores the SHELL variable and runs /bin/sh –ex?  This would explain much.

 

--Rob

Click here to report this email as spam.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/55DC7498.70609%40recommind.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages