14

I often getting confused with bash and shell. Are they same? If I want to learn the bash, will it be covered with Linux shell programming related books? I use Ubuntu Linux.

Edit: (Added after getting two answers.) How bash is associated with terminal?

8 Answers 8

15

bash is one particular type of Linux shell (the Bourne again shell), but there are quite a few others. In Ubuntu, bash is the default. I am sure that there are numerous shell programming books that cover it, I've read one in the past.

2
  • Actually, dash is the default Ubuntu shell. Jan 13, 2010 at 18:28
  • 3
    Dash is the default /bin/sh but the default login shell is still Bash.
    – ephemient
    Jan 13, 2010 at 18:40
11

This question is getting a little stale, but I thought I might clear up the distinction between terminal and shell as requested in the second part of the question. You can think of the terminal as a display device. These days, it is most typically a program, but there was a time when the terminal was a separate box. When you start the terminal program, it will send a wakeup signal to the local system. In the old days, the physical terminal sent a electrical signal on the (typically RS232) connection to the terminal interface. In either case, the operating system sends a "login" text back to whatever device or program sent the wakeup signal. The shell is not involved yet.

The operating system completes the login by verifying the user name and password (if any). Then it checks the verified user's entry in the password file for the name of that user's preferred shell. There is a default shell assigned when the account is created, and the user can generally change that assignment later. The OS starts the shell program, and the shell inherits the communications path connected to the terminal. The terminal program is still there, displaying the text sent to it and sending what the user types back up the communications line. Now it is the shell on the other end of the line, not the OS.

Any program can be assigned as the users initail login shell. It would be possible, but not very useful, to assign the 'date' program as the login shell. In that case, after login the user would just see the date displayed in his terminal window, and would be logged off. The difference between the terminal and the shell is that the terminal is always there, listening and talking with the user. It does not interpret the keystrokes (beyond mapping to a character set). The shell is what the OS starts up (or the user later adds in stack-like fashion) to handle communications on the other end of the terminal communications line. It decides on an action to take in response to a user's keystrokes.

5

Taken from linuxcommand.gds.tuwien.ac.at:

Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.

On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Bourne shell program, sh, written by Steve Bourne) acts as the shell program. There are several additional shell programs available on a typical Linux system. These include: ksh, tcsh and zsh.

4

"bash" is one of many available "shells" for Linux i.e. "bash" typeof "shell" == true

3
  • does this means that when I open terminal from ubuntu desktop, it runs on bash? how it is associated with terminal?
    – user90150
    Jan 13, 2010 at 18:26
  • The "terminal" on Ubuntu Linux presents a window on a "dash" (a shell... or is it "bash", I am not sure now) process, yes.
    – jldupont
    Jan 13, 2010 at 18:28
  • 1
    what awful pseudo language is this? Feb 9, 2010 at 3:59
2

No. bash is one shell. Technically Linux is not a shell but in fact the kernel, but many different shells can run on top of it (bash, tcsh, pdksh, etc.). bash just happens to be the most common one.

2
  • Is ssh server expose the bash shell by default? (I don't spend more time on linux and mostly I do midnight hacking) sorry for so many questions.
    – user90150
    Jan 13, 2010 at 18:35
  • The ssh server uses the preferred login shell (see the chsh(1) man page) of the user logging in. Jan 13, 2010 at 18:36
2

No, they are not the same, and yes, linux shell programming books should have significant portions or be entirely about bash scripting.

Ubuntu is a distribution of linux which contains bash as an available shell. When you open a terminal in Ubuntu, you're opening a screen that emulates a display with a certain number of rows and columns. Bash is a program that can run on a terminal and allow you to interact with the system. It is much like the dos prompt in a command window in windows, if you are familiar with that.

You can have multiple shells, but many people prefer bash and you'll have the best luck learning it first.

Good luck!

0

Try: http://en.wikipedia.org/wiki/Unix_shell Hint: Bash is a type of Unix shell.

0

In order to have certain scripts be portable between AIX and Linux I have had to do have specific logic to determine the box type and run variations of certain commands.

For exmaple:

If you were using a '\c' to prevent a newline at the end of an echo, you'll have to change to "echo -n".

Also, the ping syntax changes a little.

I would think the majority of commands would be approx the same with some slight nuance changes every now and again.

1
  • ping syntax has nothing to do with the shell. In fact very little of this answer has much to do with the OP's question. Jan 13, 2010 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.