Solved

unix exit command question.

Posted on 2001-07-24
5
323 Views
Last Modified: 2012-05-04
I'm working on a script and one of the commands is:
E.   Exit from UNIX

I have this for the command:
E)
 echo "Do you want to exit UNIX"
  set reply = $<
  if ($reply == 'y') then
  exit
  if ($reply == 'n') then
  echo "Hit <ENTER> to continue:  \c"

when I run the script I get this error:

menu[5]: 0403-057 Syntax error at line 83 : `then' is not expected.

How do I get this command to work.
Thanks in advance
0
Comment
Question by:scottkey81
  • 3
5 Comments
 
LVL 6

Expert Comment

by:bira
ID: 6314585
#!/bin/ksh
 echo "Do you want to exit UNIX"
 read reply
 if [ $reply = 'y' ]; then
       exit
 fi
 if [ $reply = 'n' ]; then
 echo "Hit <ENTER> to continue:  \c"
 read
 fi
0
 
LVL 11

Expert Comment

by:griessh
ID: 6314589
From your snippet I would suggest you are missing the
#!/bin/csh
statement at the beginnig of your script (to start a new cshell).
Further you will get errors, because each if has to be closed by a 'fi' statement.

Good Luck
======
Werner
0
 
LVL 6

Expert Comment

by:bira
ID: 6314612
0
 
LVL 6

Accepted Solution

by:
bira earned 50 total points
ID: 6314613
If you decide to use it in ksh, and your intention is
to terminate the Unix session when y entered, here goes a
new version:

 #!/bin/ksh
 echo "Do you want to exit UNIX"
 read reply
 if [ $reply = 'y' ]; then
       logout
 fi
 if [ $reply = 'n' ]; then
 echo "Hit <ENTER> to continue:  \c"
 read
 fi
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6314728
griessh, if you suggest csh, then te if statement must be terminated with endif. fi is sh (ksh, etc.) syntax.

bira, logout does not work from within a script in this way.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EMC VNX  storage pool  Vs  raid group  question 3 135
NTP Server in VMware 5 225
Access Required to Read Linux Security Settings and User Permissions 13 133
Access_log 17 121
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question