resource-agents icon indicating copy to clipboard operation
resource-agents copied to clipboard

Low: bash can do find and replace

Open grooverdan opened this issue 10 years ago • 4 comments

Ok, shelling out to do find and replace when sh does it so easily urked me enough to write a patch.

tested with ./lvm.sh meta-data

grooverdan avatar Dec 16 '14 11:12 grooverdan

is this a bashism?

davidvossel avatar Dec 16 '14 18:12 davidvossel

Nope, all sh, substitution ${a//x/y} and removing prefix/suffixes ${a%%xx} / ${a#xx} in the other PRs

and aside from that #!/bin/bash is the header of each file here.

grooverdan avatar Dec 16 '14 22:12 grooverdan

Note that while ${a#xx}, ##, %, %% are portable, ${a/x/y} is not. try yourself: dash -c 'X=AAA; echo ${X//A/B}'

Which means these changes are ok for any resource agent with #!/bin/bash, but not for those that announce themselves as #!/bin/sh

I did not check if you hit any of the latter, so your change may even be ok, and only the statement "all sh" was wrong...

lge avatar Dec 17 '14 01:12 lge

thanks @lge for the corrections. Will keep that in mind. Good to know dash does a good test.

grooverdan avatar Dec 17 '14 02:12 grooverdan