0

I've a simple shell script that does something like this:

#!/usr/bin/bash
while read line; do
   *prints menu*
   *process 1* (e.g. pid=500)
   sleep 2
   *process 2* (e.g. pid=502)
   *while process 1 is active*; do
      sleep 1
    kill -9 502

On the first while cycle, everything goes on the right place and if process 1 terminates before process 2 then it is killed. The problem is on the second cycle onwards: when the i-th cycle starts, it always prints something like this:

script.sh: line "n": 502 Killed             ( python3 program_name argv[1] ecc...)

Anyone know how to avoid this print? The script should work (I checked with ps -a and when pid 500 dies, pid 502 gets killed immediately) but that print is not elegant.

gdonut98
  • 11
  • 4
  • Check this https://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash – AlecTMH Jul 22 '21 at 15:42
  • 2
    The use of `kill -9` in a script is very bad style. – Cyrus Jul 22 '21 at 16:17
  • How are you running the script? The status should only be reported in an interactive shell, so I suspect you are doing something like `. ./script.sh` rather than `bash script.sh`. – chepner Jul 22 '21 at 17:05

1 Answers1

0

if you do not want the stdout only for a command,

command > /dev/null

if you do not want the stderr only for a command,

command 2> /dev/null

if you do not want both stdout and stderr output for a command only,

command > /dev/null 2>&1

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
  • I did this but it keep to print it :l, I found a solution here btw: https://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash – gdonut98 Jul 23 '21 at 16:50