0

i'm trying to create a simple script for ARM cross compiler toolchain. When i try to debug with

#!/bin/bash
read VAR
echo `qemu-arm -g $VAR file &`

I should get a output like "[13] 22189", in this way i can use the other command:

gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file fileName'  -ex ' target remote localhost:$VAR"

but i don't get any output. I'm not a expert about bash script but this script can help me so much because commands aren't easy to remember. If someone can help me, i would appreciate so much

  • I don't know what you're asking but `read $VAR` is wrong, it should be `read VAR`. – oguz ismail Jun 04 '21 at 08:06
  • You are right, thank you! I wrote wrong but i have the same problem – Ahmad Shatti Jun 04 '21 at 08:09
  • 2
    @AhmadShatti: IMO, the `echo` is pointless. Just do a `qemu-arm -g "$VAR" file &`, or maybe a `nohup qemu-arm -g "$VAR" file &`. – user1934428 Jun 04 '21 at 08:12
  • Are you trying to capture the process ID of the backgrounded process? If so, don't use backticks -- those capture output *from the command*, but the "[13] 22189" is printed *by the shell*. If you want the process ID, background it normally, then use `$!` to get its PID. – Gordon Davisson Jun 04 '21 at 08:22
  • maybe with this image, i can explain better https://imgur.com/gallery/R5n3mAn @user1934428 i tried both commands but they don't work – Ahmad Shatti Jun 04 '21 at 08:49
  • @AhmadShatti I still don't understand what you're trying to do. Maybe it would help if you showed the commands you're trying to automate (i.e. what does it look like when you do it manually?) – Gordon Davisson Jun 04 '21 at 09:08
  • @GordonDavisson i'm trying to debug a file.s, manually command are: "arm-linux-gnueabihf-gcc hello.s -o hello_arm_static -static -ggdb3" for compile, and "qemu-arm -g 12345 hello &" "gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file hello' -ex ' target remote localhost:12345' " for debug. My problem is the command "qemu-arm -g 12345 hello &". The correct output is like in the image I sent you before – Ahmad Shatti Jun 04 '21 at 09:17
  • Follow @user1934428's advice: remove the `echo` and backticks. – Gordon Davisson Jun 04 '21 at 09:40
  • Resolved!! But now i have a new problem... https://stackoverflow.com/questions/67836172/bash-script-shell-input-variables – Ahmad Shatti Jun 04 '21 at 11:10

0 Answers0