Score:0

Launching bash file exits after first command with "Terminated" message while it runs well within terminal

in flag

I am on Ubuntu 22.04 platform. I made a simple push button GUI in c named t2s and placed it in ~/.local/bin whose path is added to PATH environment variable. While I am pressing down the button, it is recording voice from mic to a temp file. When I release the button GUI exits. I run the following line which works well within terminal:

 t2s && notify-send -u normal  -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"

Voice is sent to whispercpp speech to text engine and transcribed. The result is shown in the notification on the screen.

But when I place that line in a file and launch it, such as:

 #!/bin/bash

 t2s && notify-send -u normal  -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"

 exit 0

it only executes the GUI button, when the GUI exits after releasing button, it doesn't execute

 notify-send -u normal  -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"

part

What am I doing wrong?

EDIT:

I also tried it like this:

#!/bin/bash

t2s
TEXT=$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
notify-send -u normal  -t 10000 $TEXT

Nothing's changed.

EDIT:

I noticed that it's related to shell internals.

I still don't know how to overcome it.

ar flag
I would get rid of the `&&` and break the single line into 3 lines. First line: `t2s`. Second line: `TEXT=$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"`. Third line: `notify-send -u normal -t 10000 $TEXT`. I would also check the location of the temp `mic.wav` file.
in flag
@user68186 thank you for responding. I tried it before but I did it again, unfortunately it fails.
ar flag
Let's try `echo $TEXT` after second line, before the `notify-send ...` line. Let me know if you see any text in the terminal resembling the recorded audio.
in flag
@user68186 I've just tried it. It exits right after `t2s` with `Terminated` message. It appears to be related to https://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash
Score:0
in flag

After reading the following links:

I understood that termination of ffmpeg line which was executed within GUI button causes bash shell to terminate after t2s GUI. I worked around the issue by chatching up SIGINT and SIGTERM signals within a trap block and then I placed the rest of the commands in it after t2s:

#!/bin/bash

trap_with_arg() { # from https://stackoverflow.com/a/2183063/804678
  local func="$1"; shift
  for sig in "$@"; do
    trap "$func $sig" "$sig"
  done
}

stop() {
  trap - SIGINT EXIT
  printf '\n%s\n' "received $1, killing child processes"
  notify-send -u normal  -t 10000 "$(whispercpp -m /home/**/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
  kill -s SIGINT 0
}

trap_with_arg 'stop' EXIT SIGINT SIGTERM SIGHUP

t2s

exit 0
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.