Difference between revisions of "Shell"

From Hackepedia
Jump to navigationJump to search
(New page: A shell is both a command language and a programming language that provides an interface to any UNIX based operating system UBO. The most popular shell by far is [http://www.gnu.org/...)
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
A shell is both a command language and a programming language that provides an interface to any UNIX based operating system [[UBO]].  
+
A shell is both a command language and a programming language ([[interpreter|interpreted]]) that provides an interface to any UNIX based operating system [[UBO]].  
  
 
The most popular shell by far is [http://www.gnu.org/software/bash/ bash] which is provided by the GNU team. There are several other popular shells, depending on your requirements and skillset:
 
The most popular shell by far is [http://www.gnu.org/software/bash/ bash] which is provided by the GNU team. There are several other popular shells, depending on your requirements and skillset:
Line 18: Line 18:
  
 
as you can see, there is where you will change items such as your [[PATH]]
 
as you can see, there is where you will change items such as your [[PATH]]
 +
 +
 +
== Scripting ==
 +
 +
If you want to learn shell scripting, we recommend you start with [[sed]], [[awk]] and [[grep]]. All three are very powerful and each will take years to master. An example of each:
 +
 +
This will substitute any line with the word root in it in /etc/passwd with an empty space in place of "root":
 +
$ [[sed]] s/root//g /etc/passwd
 +
 +
This will show you the fifth field in /etc/passwd if you seperate each field with a colon:
 +
 +
$ [[awk]] -F: '{print $5}' /etc/passwd
 +
 +
Finally, this will show you every line in /etc/passwd with the word "root" in it
 +
$ [[grep]] root /etc/passwd

Latest revision as of 14:22, 17 July 2007

A shell is both a command language and a programming language (interpreted) that provides an interface to any UNIX based operating system UBO.

The most popular shell by far is bash which is provided by the GNU team. There are several other popular shells, depending on your requirements and skillset:

  • csh
  • tcsh
  • sh
  • ash
  • zsh

to see what shell you are using:

$ echo $SHELL

which is one of the variables that can be found in your environment. You can get a list of all of your environment variables:

$ env

as you can see, there is where you will change items such as your PATH


Scripting

If you want to learn shell scripting, we recommend you start with sed, awk and grep. All three are very powerful and each will take years to master. An example of each:

This will substitute any line with the word root in it in /etc/passwd with an empty space in place of "root":

$ sed s/root//g /etc/passwd

This will show you the fifth field in /etc/passwd if you seperate each field with a colon:

$ awk -F: '{print $5}' /etc/passwd

Finally, this will show you every line in /etc/passwd with the word "root" in it

$ grep root /etc/passwd