LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   What is Linux Shell? (https://www.linuxquestions.org/questions/linux-general-1/what-is-linux-shell-4175479167/)

PravinGanore 10-01-2013 02:12 AM

What is Linux Shell?
 
Computer only knows and understands the language of zeros and ones which is known as binary language. In early days of computing, instruction provided using binary language, which is difficult for all of us, to understand, read and write. Therefore, in operating system there is special program called shell. Shell accepts your instruction or commands in english language and if it is a valid command, kernel will process your request.

Shell is a user program or it is environment provided for user interaction. It a command language interpreter that executes commands read from the standard input device (keyboard) or from a file.

To find all available shells in your system type following command:

Quote:

$ cat /etc/shells
Note that each shell does the same job, but each understand different command syntax and provides different built-in functions.

Under MS-DOS, shell name is COMMAND.COM which is also used for same purpose, but it is not as powerful as our Linux Shells are!

Command line interface (CLI)

Shell provides an interface to the Linux where you can type or enter commands using the keyboard it know as command line interface (CLI).

To find out your current shell type following command:

Quote:

$ echo $SHELL
$ ps $$

druuna 10-01-2013 03:25 AM

Quote:

Originally Posted by PravinGanore (Post 5037770)
To find out your current shell type following command:
Code:

$ echo $SHELL

This isn't true.

The SHELL variable is bash specific:
Code:

$ echo $SHELL
/bin/bash
$ csh  # start csh
% echo $SHELL
/bin/bash
% ksh  # start ksh
$ echo $SHELL
/bin/bash
$

SHELL was set by the initial bourne again shell and not touched by csh and/or ksh.

TB0ne 10-01-2013 10:21 AM

Quote:

Originally Posted by PravinGanore (Post 5037770)
Computer only knows and understands the language of zeros and ones which is known as binary language. In early days of computing, instruction provided using binary language, which is difficult for all of us, to understand, read and write. Therefore, in operating system there is special program called shell. Shell accepts your instruction or commands in english language and if it is a valid command, kernel will process your request.

Shell is a user program or it is environment provided for user interaction. It a command language interpreter that executes commands read from the standard input device (keyboard) or from a file.

A little bit right, but wrong. Please read the correct definition:
http://en.wikipedia.org/wiki/Linux_Shell
Quote:

To find all available shells in your system type following command
Note that each shell does the same job, but each understand different command syntax and provides different built-in functions.
No, sorry...the commands entered are LINUX commands...the options for all of them remain the same. Typing in "ls" in csh is the same as typing it in on bash or ksh. The command-line options remain the same too. The scripting functions change.
Quote:

Under MS-DOS, shell name is COMMAND.COM which is also used for same purpose, but it is not as powerful as our Linux Shells are!
Partially true, but Windows batch programming is every bit as complex as bash scripting can be.

TobiSGD 10-01-2013 10:51 AM

Quote:

Originally Posted by TB0ne (Post 5038024)
No, sorry...the commands entered are LINUX commands...the options for all of them remain the same. Typing in "ls" in csh is the same as typing it in on bash or ksh. The command-line options remain the same too. The scripting functions change.

Not entirely true. There are commands that are inbuilt to the shell and may have different options on different shells. Such commands are for example cd, pushd, popd, alias and ulimit. For a complete list of inbuilt commands for Bash have a look here: https://www.gnu.org/software/bash/ma...-Builtins.html

TB0ne 10-01-2013 02:23 PM

Quote:

Originally Posted by TobiSGD (Post 5038042)
Not entirely true. There are commands that are inbuilt to the shell and may have different options on different shells. Such commands are for example cd, pushd, popd, alias and ulimit. For a complete list of inbuilt commands for Bash have a look here: https://www.gnu.org/software/bash/ma...-Builtins.html

Good point, and one I neglected to consider. I was thinking of 'commands' in general, without making the distinction between the inbuilt ones vs. 'external' commands.

vishal.upadhye 10-03-2013 07:35 AM

simple way to define a shell is CLI with the kernel so that user can inter-react eaisily .
here are several different shells available for Unix; the most popular are described here.

You can use any one of these shells if they are available on your system. And you can switch between the different shells once you have found out if they are available.

Bourne shell (sh)
C shell (csh)
TC shell (tcsh)
Korn shell (ksh)
Bourne Again SHell (bash)

jheengut 12-10-2013 10:08 AM

Quote:

Originally Posted by druuna (Post 5037824)
This isn't true.

The SHELL variable is bash specific:
Code:

$ echo $SHELL
/bin/bash
$ csh  # start csh
% echo $SHELL
/bin/bash
% ksh  # start ksh
$ echo $SHELL
/bin/bash
$

SHELL was set by the initial bourne again shell and not touched by csh and/or ksh.


will this work

Quote:

echo $0

druuna 12-10-2013 10:43 AM

Quote:

Originally Posted by jheengut (Post 5078456)
will this work
Code:

echo $0

Start a c shell (csh) and try ;)

EDIT: Using ps -p $$ shows the current shell that is being used.

jheengut 12-25-2013 02:14 PM

Quote:

Originally Posted by druuna (Post 5078468)
Start a c shell (csh) and try ;)

EDIT: Using ps -p $$ shows the current shell that is being used.



csh
# echo $0
csh
#

druuna 12-25-2013 02:19 PM

@jheengut:
Code:

[plains] druuna ~ $ csh
% echo $0
No file for $0.


% ps -p $$
  PID TTY          TIME CMD
14558 pts/0    00:00:00 csh


jheengut 12-26-2013 09:58 AM

root@:/home/pritvi# which echo
/usr/bin/echo
root@:/home/pritvi# echo $0
/bin/bash
root@:/home/pritvi# csh
# which echo
Quote:

echo: shell built-in command.
root@:/home/pritvi# ps -p $$
PID TTY TIME CMD
1704 pts/8 00:00:00 bash
root@:/home/pritvi# csh
# ps -p $$
PID TTY TIME CMD
5206 pts/8 00:00:00 csh


# /usr/bin/echo $0
csh


why does your's echo does not work ???

druuna 12-26-2013 10:45 AM

Quote:

Originally Posted by jheengut (Post 5087173)
root@:/home/pritvi# which echo
/usr/bin/echo
root@:/home/pritvi# echo $0
/bin/bash
root@:/home/pritvi# csh
# which echo
root@:/home/pritvi# ps -p $$
PID TTY TIME CMD
1704 pts/8 00:00:00 bash
root@:/home/pritvi# csh
# ps -p $$
PID TTY TIME CMD
5206 pts/8 00:00:00 csh


# /usr/bin/echo $0
csh


why does your's echo does not work ???

Mine does work. Looking at the csh manual page I see this:
Quote:

$0 Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
and this:
Quote:

After processing of flag arguments, if arguments remain but none of the -c, -i, -s, or -t options were given, the first argument is taken as the name of a file of commands to be executed. The shell opens this file, and saves its name for possible resubstitution by ‘$0’.
I installed csh but never actually use it and do not have any local csh related login files (system wide: the defaults that came with Debian).

Using ps -p $$ is the only way that I know of that returns the correct shell that is being used. All other methods I've tried and seen can go wrong in one way or another.

TB0ne 12-26-2013 12:33 PM

Quote:

Originally Posted by leethinh2612 (Post 5087208)
Cảm ơn chủ thớt, đúng topic mình đang tìm kiếm
----------------------
day lai xe

---------- Post added 12-27-13 at 12:57 AM ----------

Cảm ơn chủ thớt, đúng topic mình đang tìm kiếm
----------------------
Chữ ký ......

This is an English only forum...please re-post your comments in English, as per LQ Rules.

273 12-26-2013 03:08 PM

Quote:

Originally Posted by PravinGanore (Post 5037770)
Under MS-DOS, shell name is COMMAND.COM which is also used for same purpose, but it is not as powerful as our Linux Shells are!

Have you just copied this from a website that hasn't been updated in 20 years?
Windows (which replaced DOS over a decade ago) has cmd.exe and command.com and, more recently, PowerShell which is arguably as good as anything available for Linux. That's ignoring VBScript and Javascript used as macro languages as well as third party tools such as KixTart scripting.
Is this post the prelude to some SPAM or just ill-informed?

wstewart90 12-27-2013 04:26 AM

Powershell is nice but it still doesn't have anything on bash.


All times are GMT -5. The time now is 11:03 PM.