Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash bad substitution in script

Tags:

bash

groovy

I have some groovyscript. I execute a shell command:

sh "echo ${myParams.TEST}"

This prints:

works

Now I try to do the same but in a bash script in the shell:

sh'''#!/bin/bash
echo "${myParams.TEST}"
'''

But this gives always the same error: bad substitution

EDIT:

sh """#!/bin/bash
echo \"${myParams.TEST}\"
"""

This works: output is: works

Now I try:

sh """. ./script.sh"""

script.sh looks like:

#!/bin/bash
echo "hey"
echo '\"${myParams.TEST}\"'

Output is again:

hey
bad substitution
like image 491
DenCowboy Avatar asked Mar 27 '26 07:03

DenCowboy


1 Answers

sh """../script.sh"""

just starts shell script

and shell script don't know anything about your groovy variables

so, you have to pass values to your script like this:

sh """../script.sh \"${myParams.TEST}\" """

then you can access the value of myParams.TEST in bash by $1 as it is the first parameter for it

like image 165
daggett Avatar answered Mar 29 '26 20:03

daggett