Re: Comparing strings

From: Grant Taylor (gtaylo...)

On 7/14/21 9:42 AM, ELCV wrote:
> A new issue. I am evaluating my script so I am using echo to display
> the commands.
> My function is as follows:
> singleVolume(){
> # OS Volumes
> echo "virsh suspend $ARG"
> echo "dd if=/dev/vg0/$ARG_0 | ssh [email protected] dd of=/backup/images/$ARG_0.img"
> echo "virsh resume $ARG"
> }
> When I run my command the $ARG variable in the second line is not echoed:
> virsh suspend FOO
> dd if=/dev/vg0/ | ssh [email protected] dd of=/backup/images/.img
> virsh resume LIMS2
> So the variable and the _0 are being dropped. I've tested without
> "echo" and obtained the same result.
> If I create a new variable, SUFF="_0" and then use echo
> "dd if=/dev/vg0/$ARG$SUFF | ssh [email protected] dd
> of=/backup/images/$ARG$SUFF.img"
> It works. Is this expected? It only seems an issue using functions.

I don't know if I would /expect/ it per se or not. But I am not at all
surprised by it.

This hints at an escaping problem to me. Maybe. Maybe not.

Try changing your ssh command to be:

ssh [email protected] dd of=/backup/images/${ARG}_0.img

Avoid the abiguity of what is variable vs appended string.

Aside: That might not be the escaping that I was referring to as
escaping would usually be how your local shell interprets $ARG, or not,
prior to sending it to the remote shell / sub-command. Escaping is more
about where the expansion should happen. And I think your primary /
current issue is what is the variable vs data.

> Thanks.

You're welcome.

Grant. . . .
unix || die

Share |
Comparing strings... by ELCV on Jul 13th 2021, 17:46
Re: Comparing strings... by Grant Taylor on Jul 13th 2021, 20:29
Re: Comparing strings... by ELCV on Jul 14th 2021, 01:53
Re: Comparing strings... by ELCV on Jul 14th 2021, 15:42