0

I'm trying to launch and kill a background process in a script, but it gives me this error:

$ bash ./test.sh
7826
: arguments must be process or job IDs

My script code is:

#!/bin/bash
./program &
p_pid=$!
echo $p_pid
kill $p_pid

Debuging:

+ p_pid=$'8527\r'
+ echo $'8527\r\r'
8527
+ kill $'8527\r'
+ ./program
: arguments must be process or job IDs

How can I resolve this error?

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Qunts
  • 41
  • 1
  • 4
  • you should insert `set -x` on the second line, then you should run again the script. `bash` will generate debug ouput. Edit the question and add these debug lines. – Jay jargot Apr 29 '16 at 18:48
  • 1
    You almost certainly have DOS line endings in your script. The error message is actually something like `kill 7826\r: arguments must be ...`, and the `\r` causes the rest of the message, starting with `:`, to be printed at the beginning of the line. – chepner Apr 29 '16 at 18:55
  • @chepner was right `tr -d '\r' myscript > cleanscript.sh` then run the script again – Jay jargot Apr 29 '16 at 19:44

0 Answers0