sed
keeps giving invalid arithmetic operator error. I am trying to assign the output of sed to a variable.
This one works,
var=$(sed -e 's/"currentGeneration":5010/"currentGeneration":5011/' <<< $content )
but when I try to do the same with variable instead of 5010 and 5011, it fails with invalid arithmetic operator
var=$((sed -e 's/"currentGeneration":$currg/"currentGeneration":$nextg/' <<< $content ))
I tried below also but it won't substitute anything.
var=$(sed -e 's/"currentGeneration":$currg/"currentGeneration":$nextg/' <<< $content )
I am pretty sure I am missing something basic. Learning shell scripting on the job :(
$( ... )
is command substitution,$(( ... ))
is arithmetic expansion. (If you're running that on an interactive Bash, the error message should begin withbash: ...
, implying it's from Bash and not sed.) I can't tell any reason why the parentheses would have been doubled there. The other issue is with double quotes""
vs. single quotes''
, see What is the difference between the "...", '...', $'...', and $"..." quotes in the shell? – ilkkachu Sep 27 '21 at 15:18