how to exit a script

Asked by Brad Ganson on 2010-08-14

#!/bin/bash
cat /proc/asound/version
echo
echo -e "If version = 1.0.23 then press y to end this installation:\c"
read word
if [$word=y] then
 echo "will exit now."
 exit
fi
echo "not an exit."
exit

why doesn't exit work to end the script????

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Solved by:
Brad Ganson
Solved:
2010-08-24
Last query:
2010-08-24
Last reply:
2010-08-15

This question was reopened

Why not use:

#!/bin/bash
if grep -q 23 /proc/asound/version; then
  echo "Version is 23"; exit 0
else
  echo "Version is NOT 23"; exit 1
fi
exit 1

This mean you don't need user input, the script does the test itself. The exit 0 means all is well and you can use the output in other scripts, exit anything other than 0 means an issue occured.

Brad Ganson (bganson) said : #2

thank you

Brad Ganson (bganson) said : #3

is the exit 1 an end to the script? that is what i need

Brad Ganson (bganson) said : #4

sorry...exit 0 means we need to go no further, would still like to know why exit doesn't work

I'd have though it would be exit 1, it means the file didn't output or the grep went wrong.

Glad you got the gold. You didn't need the user to input in your initial code though ;)

Brad Ganson (bganson) said : #6