Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

unix exit command question.

Posted on 2001-07-24
5
Medium Priority
?
342 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 200 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses

636 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