how to exit a script

Asked by Brad Ganson

#!/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:
Last query:
Last reply:

This question was reopened

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

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.

Revision history for this message
Brad Ganson (bganson) said :
#2

thank you

Revision history for this message
Brad Ganson (bganson) said :
#3

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

Revision history for this message
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

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

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 ;)

Revision history for this message
Brad Ganson (bganson) said :
#6