Shell Script with curl works on terminal but not as menu launcher.
Hello friends Happy New Year.
I have a question because I have a problem to apply a simple script as a launcher click to execute in terminal and auto use curl that have wttr.in as target. If I directly put this command on terminal he works → Code:
$ bash -x /home/joao/.config/tempo.sh Code:
#!/usr/bin/env bash Code:
[Desktop Entry] Exec=/usr/bin/bash -c /home/joao/.config/tempo.sh Exec=/usr/bin/env bash -c /home/joao/.config/tempo.sh Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh;$bash' " ... So now i'm curious why script works if I directly use the command with path on terminal but not as a launcher. Thanks. |
Try providing the full path to curl in the script...
|
is tempo.sh marked executable?
Code:
chmod +x tempo.sh |
Quote:
The second would be to have it use the interpreter directly instead of depending on an indirect reference from the environment: Code:
#!/bin/bash Then invoke the script like this: Code:
Exec=/home/joao/.config/tempo.sh Code:
#!/bin/bash |
Quote:
I edit the file like this → #!/usr/bin/env bash PATH=/usr/local/bin:/usr/bin:/bin curl https://wttr.in/chaves And I try to put the file on a /bin path on my current user and I also modify the launcher Exec command. No work. Of course I already check the permission execution mentioned on command → chmod +x ... Thanks for help. |
I would add some echo commands to that script, like echo started.
And also I would redirect its output into a logfile. Adding set -xv at the beginning also may help (to find the reason). |
It does work, you just can't see it.
I assume when you click on the shortcut, a terminal window opens, appears to do nothing and then closes. This is normal. Quote:
If you want to see the output in the terminal window you need to pause your running script Code:
#!/bin/bash |
I Tried the code script →
#!/bin/bash curl https://wttr.in/chaves read -p "Press any key to continue" And still do nothing the "Press any key to continue" dont appear also and the terminal open and do nothing. |
Does the script still work from the command line but not the launcher?
As a frame of reference I am testing your script on Ubuntu version 19. |
Quote:
|
how do you know that?
|
Quote:
/home/joao/.config/tempo.sh /home/joao/bin/tempo.sh the content of scripth (.sh file) is → Code:
#!/bin/bash $/home/joao/.config/tempo.sh You can test this on your system copy the script, put on a file .txt like tempo.txt, rename the file to .sh like tempo.sh view permissions or pass the chmod command to the file execution permissions - chmod +x /path/to/your/file.sh. Copy te file and put on a path of your current user /home/user/tempo.sh or ~ /tempo.sh and run it (~ - means your current user folder - home). So because this I can see the script works when I run it specifiyng directly the path on terminal but for some reason when I do a a launcher to be executed in terminal he dont works. |
Because the launcher does not use any terminal (you will not see the result in your terminal).
You need to save the downloaded content as it was suggested in post #4 and/or you can add debug info (post #6). Also you can specify a terminal in the Exec line, something like this: Code:
Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh' " |
Quote:
Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh;$bash' " Dont work on launcher open terminal only do nothing. In terminal here the outputs → $ "bash -c '/home/joao/.config/tempo.sh' "bash: bash -c '/home/joao/.config/tempo.sh' : Ficheiro ou directoria inexistente $ bash -c '/home/joao/.config/tempo.sh' Weather report: chaves ... → works fine |
yes, what you entered is wrong. You need to modify it. That's why I told you to test it.
|
Quote:
This still do nothing when I specify on launcher file. Thanks for help. |
There should be no quotes around what you are runnning, the items after the -e are interpreted verbatim,
Code:
Exec=lxterminal -e /home/joao/.config/tempo.sh Code:
Exec=lxterminal -e sh -c '/home/joao/.config/tempo.sh' |
In the launcher with or without quotes no work.
If I put the lxterminal -e /home/joao/.config/tempo.sh in terminal this is the result → $ lxterminal -e /home/joao/.config/tempo.sh /run/user/1000/.lxterminal-socket-:0 Opens new window with new terminal - lxterminal - and code work. |
Is the desktop entry located in the ~/Desktop directory?
Does its properties allow launching? What do you see when you right click on the icon? |
Quote:
http://lxmed.sourceforge.net/ I already use other launchers to add in the meu and works well example → Code:
#!/bin/bash If I click on the launcher with right click I have options like → launch, launch in terminal, Open with etc... |
All times are GMT -5. The time now is 03:21 AM. |