![]() |
|
Open a bash script for see the result. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88) +---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85) +---- Thread: Open a bash script for see the result. (/showthread.php?tid=5975825) |
Open a bash script for see the result. - hack3rcon - Jun 2, 2019 Hello. When I write a script like "ping google.com" and double click on it then the window opened and closed. How can I keep it open and see the result? Thanks. RE: Open a bash script for see the result. - Deathbox - Jun 2, 2019 Open command prompt or linux terminal and type Code ping google.co.ukIf it's a shell script: Code #!/usr/bin/envWindows Batch/CMD script (.cmd/.bat): Code ping google.co.ukRE: Open a bash script for see the result. - hack3rcon - Jun 3, 2019 (Jun 2, 2019 03:18 AM)Deathbox Wrote: Open command prompt or linux terminal and typeThanks. Why "sleep 3"? I like to see the result until I canceled it. RE: Open a bash script for see the result. - elbone - Jun 3, 2019 (Jun 3, 2019 05:32 AM)hack3rcon Wrote: Thanks. That's for a Shell script. RE: Open a bash script for see the result. - Deathbox - Jun 3, 2019 Try sleep integer in the terminal. It's just how long to wait in seconds. I added that line so you can see the result before the application crashes. You need to pause it or add a time limit which is what you've done with the sleep command. If you want a pause button similar to pause function in batch on MS Windows, you could use the read command instead of a time limit. Code read -p "This is a message. push a button to resume"(Jun 3, 2019 06:07 AM)elbone Wrote: That's for a Shell script. Yes, @OP. It's too late for me to edit my original post but I meant the bash shell (assuming you're using bash) on most Linux systems in the first code snippet that should be saved as a .sh file; as opposed to the following code snippet for a MS Windows batch file which needs the extension .CMD or .BAT. Sorry about the mix up. RE: Open a bash script for see the result. - hack3rcon - Jun 7, 2019 (Jun 3, 2019 07:40 AM)Deathbox Wrote: Try sleep integer in the terminal. It's just how long to wait in seconds. I added that line so you can see the result before the application crashes. You need to pause it or add a time limit which is what you've done with the sleep command. If you want a pause button similar to pause function in batch on MS Windows, you could use the read command instead of a time limit.When I execute below commands as .sh file then it show me a black window: Code #!/usr/bin/envCode #!/usr/bin/envRE: Open a bash script for see the result. - Deathbox - Jun 7, 2019 (Jun 7, 2019 04:05 AM)hack3rcon Wrote: When I execute below commands as .sh file then it show me a black window: My bad buddy, yeah the shebang line should be #!/usr/bin/env python. It can also be #!/usr/bin/python but the first is recommended. If you don't use either, I believe it uses /usr/bin/python by default. Using the env just means that it will use the first python interpreter in the $path. You can use the following to set the default interpreter. It's common to have 2.7 and 3.x installed. Code sudo update-alternatives --config pythonOr you can do it manually specifying which interpreter Code #!/usr/bin/pythonIf you take a look in /usr/bin/ you can see the packages installed on your system. In the image below you can see I have several versions of Python located at /usr/bin and so I would be able to use any of them. Spoiler (Click to View) RE: Open a bash script for see the result. - datguy.dev - Jun 7, 2019 wait: https://linuxhint.com/wait_command_linux/ But you can also do something like xterm -hold -e yourscript.sh RE: Open a bash script for see the result. - hack3rcon - Jun 7, 2019 (Jun 7, 2019 05:58 AM)Deathbox Wrote: My bad buddy, yeah the shebang line should be #!/usr/bin/env python. It can also be #!/usr/bin/python but the first is recommended. If you don't use either, I believe it uses /usr/bin/python by default. Using the env just means that it will use the first python interpreter in the $path. You can use the following to set the default interpreter. It's common to have 2.7 and 3.x installed.It is a bash but why use Python? RE: Open a bash script for see the result. - Deathbox - Jun 8, 2019 (Jun 7, 2019 10:46 PM)hack3rcon Wrote: It is a bash but why use Python? I tend to have threads open from the Python section, I'm very sorry lol. Yeah for bash, it's just Code #!/usr/bin/env bashI'll leave the previous reply, as it explains why you should use env. RE: Open a bash script for see the result. - hack3rcon - Jun 8, 2019 (Jun 8, 2019 09:11 AM)Deathbox Wrote: I tend to have threads open from the Python section, I'm very sorry lol. Yeah for bash, it's just Thank you so much. |