0

I have a simple shell script that includes the following lines

echo "Hello"

g++ main.cpp -o mainOutput

echo "Shell script ended!"

When I run the script using a terminal, it echoes the messages properly. It doesn't act the same if I run it by double-clicking on it. It just creates the mainOutput without any messages.

I want my script to act the same in both situations. What do you think that I am doing wrong?

  • 1
    does this answer your question? https://askubuntu.com/a/20353/945853 – nouvist Feb 16 '21 at 09:25
  • Unfortunately, no. The accepted answer suggests appending $SHELL at the end of the script. But, it didn't change anything – Caglayan DOKME Feb 16 '21 at 09:39
  • 1
    If you double-click on it to run it, that doesn't start a terminal usually, so there's nowhere to show the echoed messages. But the echo commands do run. – muru Feb 16 '21 at 09:54
  • @muru So you say that running a shell script by double-clicking on it is not the proper way. – Caglayan DOKME Feb 16 '21 at 09:56
  • Depends on what you want to do. You could, for example, detect if the script is running in a terminal (e.g., if [[ -t 0 ]] ...) and then use echo or use zenity to show messages otherwise. – muru Feb 16 '21 at 09:58
  • I answered a related question yesterday https://askubuntu.com/questions/1316538/how-to-check-already-executed-programs-in-linux/1316591#1316591 You might find this approach helpful – PonJar Feb 16 '21 at 10:13

0 Answers0