[chef] Re: Re: Chef messing up sed commmand


Chronological Thread 
  • From: Hamza Khan-Cheema < >
  • To:
  • Subject: [chef] Re: Re: Chef messing up sed commmand
  • Date: Mon, 22 Apr 2013 11:16:47 +0300

Thanks for the quick reply :)

I didn't know about <<-'EOF' 

Kind Regards
Hamza Khan-Cheema

On 22 Apr 2013 11:05, "Noah Kantrowitz" < "> > wrote:

On Apr 22, 2013, at 12:48 AM, < "> > wrote:

> Hi
>
> I am trying to get a bash script to work that has a sed command in it.        The sed
> command has escape characters in it.  For some reason Chef seems to be taking
> these escape characters out and trying to execute the sed script which fails.
> The sed script works in the console
>
> Below is the original test script I made. This works as expected.
>
> if [ $(grep -c postrotate $1) -ne 0 ]; then
>  if [ $(grep -c checksum_log.sh $1) -ne 1 ]; then
>    sed -i 's/endscript/\/usr\/bin\/checksum_log.sh $1\n endscript/' $1
>  fi
> fi
>
> The Bash script block in Chef is the same as above contained within a <<-EOF
> block with $1 being replaced with a file name.

Make that <<-'EOF' to make it a non-interpolated string block, otherwise you have to deal with Ruby string formatting on top of Bash formatting. You can also use %q[...]

--Noah





Archive powered by MHonArc 2.6.16.

§