Solved

unix exit command question.

Posted on 2001-07-24
5
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

724 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