ThinkBlog

philosophy :: psychology :: theology :: technology

10 November 2003

Linux Tip 004 - 2 ways to quit bash

16:34:15 :: [technology &c.] :: 1108 words

     Most people familiar with Linux or UNIX have become, by necessity or curiosity, have become acquainted over the course of their usage with the Bourne Again SHell, known to most simply as “bash”.1 A shell like bash is a way for the user to interact with the machine locally (sitting at the machine physically) or remotely (as across a network or the Internet as such) without all the superfluous “blinkies” and graphical augmentation that can slow even a LAN2 connection down.3 But the advantages of bash or a text-based connection should be discussed at length at another time.

     When one wishes to exit the bash shell, one usually types “exit” and presses Enter, at which point the shell itself will terminate and, in the case of SSH connections (Secure SHell across a network—encrypted data so as to keep passwords and data private), the connection will be dropped and that instance of the server terminated.

     There is another way of exiting bash that may or may not be more efficient: Ctrl+D is the EOF, or “End Of File” character. When you have a file on your computer, it ends with this invisible character to tell the program that’s reading the file “Okay, you’ve reached the end; don’t go any farther.” Well, so it is with bash. If you want to exit the shell quickly, you can hold down the “Ctrl” (Control) key and press `d’4 to send an EOF character to the shell and force it to terminate.

     Sometimes, though, this is unacceptable. If you want to terminate an instance of `cat’ because, for instance, you forgot to pipe the output to grep so everything from oh, say, /var/log/messages is spewing to your console!5 You can terminate that program using ^D. But if you accidentally press that twice, it could cause bash to exit, which is not necessarily acceptable.

     The bash shell uses an internal variable called IGNOREEOF which, if set to a positive number, will ignore that many ^D characters from the standard input (that is, the keyboard). If you want it to ignore zero EOF characters, you can add to your ~/.bash_profile6 the line “unset ignoreeof”. Or, if you want bash to ignore them, set it to some number in that same profile such as, for example, 10: “ignoreeof=10″.

     Hope that helps; and happy computing!

My thanks to the Happy Hacker - UNIX Yahoo! Group for this information; this Linux Tip comes from the thread on that list from mid-April 2003.

[1] You may notice that I will consistently use quotation marks inside of periods when referring to Linux programs or anything having to do with the command line, even though this is not proper English. This is a deliberate attempt to help the reader understand exactly what commands must be typed—”bash” on the Linux command line will invoke another instance of the shell itself, whereas “bash.” will render a “command not recognized” error.

[2] LAN stands for Local Area Connection; when you are connected through a network as at a corporate office or any way that chains several machines together in a common network that is literally localized (within a room, or floor, or building, &c.) and need not be accessed through the Internet proper. Thus, when you are at work in an office building or dorm room as at a college, you are said to be on a “LAN connection.” Much more loosely, the term “LAN” may become exceedingly generalized to include a direct, peer-to-peer connection between two (or more) computers linked over broadband connections such as DSL or cable. I will avoid the latter definition because of its extremely colloquial (and thus confusingly jargonic) nature.

[3] For those instances in which a GUI (Graphical User Interface, like Windows) is necessary or where bandwidth is not such a concern, VNC is an excellent and highly recommended tool.

[4] To depress the control key and then press another key on the keyboard can be written with a caret and that key in uppercase, though it is understood that unless specified you need not depress the SHIFT key at the same time in order to capitalize it. Hence, `Ctrl+d’ can be simply written as ^D. Furthermore, if you see in any text shell the caret character followed by another visible character, that is another of what is known as a “control character.” A common example is the telnet escape key, ^[; another is the backspace key, ^H. Perhaps the most common is that control character that sends an “interrupt signal” to programs: ^C. If a program is going out of control and locking up your shell, you can usually terminate it with ^C. Try those sometime when you’re in a shell!

[5] Let’s say you have a firewall script running that logs each wayward IP that tries to scan your computer’s vulnerabilities. Well, if you want to scan that file for a specific IP (say 10.20.30.40, for instance), you can run as root—that is, superuser—the following command:
# cat /var/log/messages | grep 10.20.30.40
This is a simple example; notice also that the pound sign (#) is understood, not typed. If you forget to type that last part, you could end up sending all the text of that file out to the terminal (what you’re looking at)—potentially many megabytes of text. Hence, ^D can be advantageous to terminate such a process that reads a text file like that.

[6] That is to say, the hidden file named .bash_profile (yes, that leading dot is necessary) in your home directory, denoted by the tilde (~) in most Linux shells. Another option is, if you’re root, to modify /etc/profile to modify the option globally (that is, for all users).

Leave a Reply

Linux Tip 004 - 2 ways to quit bash

16:34:15 :: [technology &c.] :: 1108 words

     Most people familiar with Linux or UNIX have become, by necessity or curiosity, have become acquainted over the course of their usage with the Bourne Again SHell, known to most simply as “bash”.1 A shell like bash is a way for the user to interact with the machine locally (sitting at the machine physically) or remotely (as across a network or the Internet as such) without all the superfluous “blinkies” and graphical augmentation that can slow even a LAN2 connection down.3 But the advantages of bash or a text-based connection should be discussed at length at another time.

     When one wishes to exit the bash shell, one usually types “exit” and presses Enter, at which point the shell itself will terminate and, in the case of SSH connections (Secure SHell across a network—encrypted data so as to keep passwords and data private), the connection will be dropped and that instance of the server terminated.

     There is another way of exiting bash that may or may not be more efficient: Ctrl+D is the EOF, or “End Of File” character. When you have a file on your computer, it ends with this invisible character to tell the program that’s reading the file “Okay, you’ve reached the end; don’t go any farther.” Well, so it is with bash. If you want to exit the shell quickly, you can hold down the “Ctrl” (Control) key and press `d’4 to send an EOF character to the shell and force it to terminate.

     Sometimes, though, this is unacceptable. If you want to terminate an instance of `cat’ because, for instance, you forgot to pipe the output to grep so everything from oh, say, /var/log/messages is spewing to your console!5 You can terminate that program using ^D. But if you accidentally press that twice, it could cause bash to exit, which is not necessarily acceptable.

     The bash shell uses an internal variable called IGNOREEOF which, if set to a positive number, will ignore that many ^D characters from the standard input (that is, the keyboard). If you want it to ignore zero EOF characters, you can add to your ~/.bash_profile6 the line “unset ignoreeof”. Or, if you want bash to ignore them, set it to some number in that same profile such as, for example, 10: “ignoreeof=10″.

     Hope that helps; and happy computing!

My thanks to the Happy Hacker - UNIX Yahoo! Group for this information; this Linux Tip comes from the thread on that list from mid-April 2003.

[1] You may notice that I will consistently use quotation marks inside of periods when referring to Linux programs or anything having to do with the command line, even though this is not proper English. This is a deliberate attempt to help the reader understand exactly what commands must be typed—”bash” on the Linux command line will invoke another instance of the shell itself, whereas “bash.” will render a “command not recognized” error.

[2] LAN stands for Local Area Connection; when you are connected through a network as at a corporate office or any way that chains several machines together in a common network that is literally localized (within a room, or floor, or building, &c.) and need not be accessed through the Internet proper. Thus, when you are at work in an office building or dorm room as at a college, you are said to be on a “LAN connection.” Much more loosely, the term “LAN” may become exceedingly generalized to include a direct, peer-to-peer connection between two (or more) computers linked over broadband connections such as DSL or cable. I will avoid the latter definition because of its extremely colloquial (and thus confusingly jargonic) nature.

[3] For those instances in which a GUI (Graphical User Interface, like Windows) is necessary or where bandwidth is not such a concern, VNC is an excellent and highly recommended tool.

[4] To depress the control key and then press another key on the keyboard can be written with a caret and that key in uppercase, though it is understood that unless specified you need not depress the SHIFT key at the same time in order to capitalize it. Hence, `Ctrl+d’ can be simply written as ^D. Furthermore, if you see in any text shell the caret character followed by another visible character, that is another of what is known as a “control character.” A common example is the telnet escape key, ^[; another is the backspace key, ^H. Perhaps the most common is that control character that sends an “interrupt signal” to programs: ^C. If a program is going out of control and locking up your shell, you can usually terminate it with ^C. Try those sometime when you’re in a shell!

[5] Let’s say you have a firewall script running that logs each wayward IP that tries to scan your computer’s vulnerabilities. Well, if you want to scan that file for a specific IP (say 10.20.30.40, for instance), you can run as root—that is, superuser—the following command:
# cat /var/log/messages | grep 10.20.30.40
This is a simple example; notice also that the pound sign (#) is understood, not typed. If you forget to type that last part, you could end up sending all the text of that file out to the terminal (what you’re looking at)—potentially many megabytes of text. Hence, ^D can be advantageous to terminate such a process that reads a text file like that.

[6] That is to say, the hidden file named .bash_profile (yes, that leading dot is necessary) in your home directory, denoted by the tilde (~) in most Linux shells. Another option is, if you’re root, to modify /etc/profile to modify the option globally (that is, for all users).

Leave a Reply


[powered by WordPress.]

For the discussion of current and historical trends in the liberal arts, information technology, and religious thought. "Of all human pursuits, the pursuit of wisdom is the more perfect, the more sublime, the more useful, and the more agreeable."

Think.

navigation

categories

search

archives

November 2003
S M T W T F S
« Oct   Jan »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

meta

ThinkBlog.org has been on the web since August 2003, with 292,449 words in 846 posts.

It is presently 09:08:50 on 18 May 2008, server side. All content except where otherwise noted Copyright © 2000-2006 Michael Phillips.

detail of Plato and Aristotle from 'The School at Athens' by Raphael

affiliations

Get Firefox! News for Nerds. Stuff that Matters.



Blogarama - The Blog Directory
Listed on Blogwise Listed on BlogShares

Blog Home

Login

33 queries. 1.260 seconds