We have couple of scripts where we want to replace variable evaluation method from $VAR_NAME
to ${VAR_NAME}
This is required so that scripts will have uniform method for variable evaluation
I am thinking of using sed
for the same, I wrote sample command which looks like follows,
echo "\$VAR_NAME" | sed 's/^$[_a-zA-Z0-9]*/${&}/g'
output for the same is
${$VAR_NAME}
Now i don't want $
inside {}
, how can i remove it?
Any better suggestions for accomplishing this task?
EDIT Following command works
echo "\$VAR_NAME" | sed -r 's/\$([_a-zA-Z]+)/${\1}/g'
EDIT1
I used following command to do replacement in script file
sed -i -r 's:\$([_a-zA-Z0-9]+):${\1}:g' <ScriptName>