1

This is a .sh file which the Ubuntu terminal runs then quits immediately. What is wrong with my script?

I don't know what my problem is – why the terminal closes after running the script and does not let me see the result. The file is shown here. Typing each command in the terminal is working, but putting them together in the file .sh, it has a problem as above.

echo echo $PATH echo nslookup www.fiu.edu echo netstate-a echo traceroute www.google.com echo ifconfig 
2
  • are you running this from the terminal, or is this script in a file that you're clicking on? additionally, the command is "netstat", not "netstate-a". Commented Nov 20, 2016 at 4:09
  • Ditto — exactly how are you running this script?  See if you can describe the sequence of events more clearly.  What happens if you run a script with just one command in it?  What if you create a script file with  no commands, and run that? Commented Nov 20, 2016 at 6:20

1 Answer 1

1

I'm not 100% sure how you are running this script, but I would re-write like so (I've also included comments):

#!/bin/sh # This is a comment line, but the line above must be the first line # and defines the shell that the rest of this script will use. echo "PATH: ["$PATH"]" # Personally, I like to include [] around vars so I can see # exactly what they are # Run a few network related commands nslookup www.fiu.edu netstate -a traceroute www.google.com ifconfig # Pause the script with a question. This will stop the script # from simply closing. Default to "y" as well so the user can # just hit the enter key to exit. echo -n "Finished? [y/n](y) " read ans # Check what the user typed - if anything if [ "$ans" = "" -o "$ans" = "Y" -o "$ans" = "y" ] then # Exit with 0 to signify no issue. exit 0 else echo "All done, so exiting anyway :]" exit 0 fi 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.