Shell command with (

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Shell command with (

Jérôme Godbout

Hi,

I’m trying to run the following command:

 

String name = ‘”download”’;

sh(script: "rm -fr -v !(${name})");

 

this results into the following string:

rm -fr -v !(“download”)

 

This run just fine into bash shell, I also tried with

/bin/bash rm -fr -v !(“download”)

But I always  end up with:

script.sh: Syntax error: "(" unexpected

 

What the hell is sh is doing? I can understand the bash is required but why is he trying to parse the command before running it?

 

Thanks,

Jerome

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/YQBPR0101MB107495F3847A77E4B8A95B27CD6F0%40YQBPR0101MB1074.CANPRD01.PROD.OUTLOOK.COM.
Reply | Threaded
Open this post in threaded view
|

Re: Shell command with (

slide
The shell is parsing the script and found an error in the syntax, it's not sh that is checking syntax. You can add a shebang line if you have something specific to bash

sh """#!/bin/bash
rm -fr -v !(${name})"""

The sh step just creates a shell script file (.sh file) and executes it, which would use the default shell. If that is not bash, then adding the shebang will cause the script to be executed under bash.

Regards,

Alex  

On Tue, Jun 30, 2020 at 9:28 AM Jérôme Godbout <[hidden email]> wrote:

Hi,

I’m trying to run the following command:

 

String name = ‘”download”’;

sh(script: "rm -fr -v !(${name})");

 

this results into the following string:

rm -fr -v !(“download”)

 

This run just fine into bash shell, I also tried with

/bin/bash rm -fr -v !(“download”)

But I always  end up with:

script.sh: Syntax error: "(" unexpected

 

What the hell is sh is doing? I can understand the bash is required but why is he trying to parse the command before running it?

 

Thanks,

Jerome

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/YQBPR0101MB107495F3847A77E4B8A95B27CD6F0%40YQBPR0101MB1074.CANPRD01.PROD.OUTLOOK.COM.


--

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVf2AXwoQUW8sx07gZJfowt8jhOjPO9P%3DA1EkiwVp-L%3D_w%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Shell command with (

Daniel Beck
In reply to this post by Jérôme Godbout


> On 30. Jun 2020, at 18:27, Jérôme Godbout <[hidden email]> wrote:
>
> What the hell is sh is doing?

It's not automatically applying your .bash_profile or .bashrc to a standalone script, as such an environment dependency would severely limit the reusability of shell scripts.

You need to set the extglob shell option for this shell script if you want to use this feature.

Compare:

1. bash -c 'ls !(foo)'
2. bash -O extglob -c 'ls !(foo)'

See `man bash`, specifically EXPANSION -> Pathname Expansion -> Pattern Matching.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3388A299-D679-4999-AA4B-D96E155FE55E%40beckweb.net.