Find the answer to your Linux question:
Results 1 to 5 of 5
I'm working on my final project (due tomorrow) and I have ONE LINE I haven't been able to figure out. We have to write a script that gives the user ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    2

    Bash script - command line to terminate session

    I'm working on my final project (due tomorrow) and I have ONE LINE I haven't been able to figure out.

    We have to write a script that gives the user a menu with options to list current directory, show path of current directory, see who's logged on, etc. Easy stuff. But the last menu option is "Exit from UNIX" and I've been going through my textbooks and googling and I can't figure out how to completely exit from within the script. "Exit" just gets me out of the script and back to the command prompt. I tried inserting an EOF but that did nothing.

    Please help!

    Thanks,
    Katie

  2. #2
    Just Joined!
    Join Date
    Jun 2009
    Posts
    44
    I think exit should work (in lowercase letters).

    Or maybe something like kill could be used.

    Third option: Wait for some more replies...

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    You could try the logout command. It's a shell command, however; it might not work for you. Effectively, it terminates a login shell, so if your menu is inside a shell script, it might work.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by Rubberman View Post
    You could try the logout command. It's a shell command, however; it might not work for you. Effectively, it terminates a login shell, so if your menu is inside a shell script, it might work.
    I just tried it in a KDE tty on my CentOS system, and got the error
    bash: logout: not login shell: use `exit'
    so I expect you are sol in this respect.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Jul 2009
    Posts
    2
    Kill worked! Thanks ADFC!

    I used:

    pid=$(ps x | grep 'Ss' | cut -d ' ' -f 2)
    pid2=$(echo $pid | cut -d ' ' -f 1)
    kill -9 $pid2

    Thank you thank you thank you.

    Katie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...