I have a sed command that works perfectly if I run it locally on Ubuntu or our embedded client Arago:
sed -i 's/export PART="$1"/export PART="A"/' flash.sh
This results in exactly what I need on both versions of sed, a line that changes:
export PART="$1"
to
export PART="A"
My problem is, I need to run that same command across a network to the embedded client so I tried this on an Ubuntu server using bash, to an Arago client using sh:
ssh -n -o stricthostkeychecking=no root@10.14.150.113 sed -i 's/PART="$1"/PART="A"/' flash.sh
Which results in a line that contains:
export PART=A"$1"
The substitution command needs to stay inside the single quotes so the double quotes are passed as literals, or maybe there’s a better way to keep the double quotes in the two strings? This looks to me like the $1 is simply being ignored like it’s empty and the "A" is being passed as A and replacing the end of PART=. I’ve tried encapsulating the command in single and double quotes, which both result in the same thing. I’ve also tried escaping the quotes with backslashes, same result. I think this is something with quote expansion with sh that I simply don’t understand. Or possibly something I don’t understand with ssh.
I’ve read through a number of other threads that are similar, but none of them dealt with using ssh to run the command remotely. I’m no longer a novice at sed, but this one has become quite the puzzle for me.
1 Answer