Reputation: 21
I am trying to write hostname
within quotes to a file. And I am doing this in a Groovy script. Here is my sh Groovy script.
sh "echo Add \"my-hostname\" \"$HOSTNAME\" >> /etc/test.conf"
My expected outcome in /etc/test.conf
should be:
Add "my-hostname" "linux-base"
But when I execute my Groovy script the outcome is:
Add my-hostname linux-base
Somebody please help me in sh
command script.
Upvotes: 2
Views: 1340
Reputation: 3370
Two workarounds:
Use single quotes:
sh 'echo Add \"my-hostname\" \"'"$HOSTNAME"'\" >> aa'
Use double escaping:
sh "echo Add \\\"my-hostname\\\" \\\"$HOSTNAME\\\" >> aa"
I am not familiar with groovy, are you sure your command doesn't need sh -c
?
Upvotes: 1