0

I want automatize these commands:

qemu-arm -g 12358 exec &
gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file exec' -ex 'target remote localhost: 12358'

if I try to create this script

#!/bin/bash
read VAR1
qemu-arm -g "$VAR1" exec &
gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file exec' -ex 'target remote localhost: "$VAR1"'

it doesn't works and I get this output

The target architecture is assumed to be arm
Reading symbols from exec...
localhost: "$VAR1": cannot resolve name: Servname not supported for ai_socktype
localhost: "$VAR1": No such file or directory.

I'm not a expert about bash script but i think the problem is about " " of second VAR1, there is a way for fix it?

  • Variables aren’t expanded within single quotes. – Biffen Jun 04 '21 at 11:12
  • In this situation of trying to understand what's going on, try to activate tracing mode, as explained in [this answer](https://unix.stackexchange.com/a/554411/279171). You will get your command lines expanded, just before they will be executed. – Bentoy13 Jun 04 '21 at 11:18

1 Answers1

1

The single quotes around this argument:

-ex 'target remote localhost: "$VAR1"'

are preventing the shell from expanding the your variable $VAR1.

You could try with double quotes instead:

#!/bin/bash
read VAR1
qemu-arm -g "$VAR1" exec &
gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file exec' -ex "target remote localhost: $VAR1"
mattb
  • 2,787
  • 2
  • 6
  • 20