Top users:

1. Nadeem
120
2. Brianna
96
3. Finley
87
4. Sigmund
87
5. Bishop
84
See all...
Win $50! Every month the top Seepedia user wins $50.

Question: What programming facilities does a shell provides?

Asked by francisca (33 points) on Aug 3, 2009  under Internet & Computers 1 answers

What programming facilities does a shell provides?


Answers
user pic
Nadeem (120 points)

on Aug 3, 2009

If you have ever coded a batch (bat) file on a windows operating system, you can consider yourself a shell scripter. Shell scripts are the counterparts of batch files on the *nix O/S, although the power of *nix scripts surpasses those of windows.



Besides being the interpreter of your commands that you type in it, the shell has some additional responsibilities when viewed as a programming environment. These are noted below:



Program Execution
Variable and file name substitution
I/O redirection
Pipeline hookup
Environment control
Interpreted programming language



The shell has its own built-in programming language. This language is interpreted, meaning the shell analyzes each statement in the language one line at a time and then executes it. Programs developed this way are easier to code and debug.



The shell programming language provides features you’d find in most other programming languages; it has looping constructs, decision-making statements and is procedure (function) oriented. However, the standard shells also lack many features such as arrays, data typing and built-in arithmetic operations. The Korn shell is much closer to traditional structured programming language, providing some limited data types (including integers and arrays) and built-in integer arithmetic.



Shell scripts have the following advantages:
They can take input from user, file and output them on screen.
Are useful for creating your own commands.
Save lots of time.
Help automate some task of day to day life.
System Administration part can be also automated.



Here are some features that can help you immensely during your use of the shell itself.



The shell stores a list of the commands that you have issued. You can navigate up and down through this list using the Up and Down Arrow keys. To repeat the last command is just Up Arrow, Enter.



nix can have some outrageously long file names, which is great when you're reading them in a list, but it is another matter when you have to type it on the command line. To make the user’s life easy, the programmers of the shells have provided a nifty little feature. Type the first letter or two and then press the Tab key. The shell will try to complete your command. If you typed enough letters to uniquely identify the file name, the shell fills the rest in for you. If the letters match multiple file names, the shell will fill in everything up to the point where they differ and wait. Hit Tab again and it will give you a list of possibilities. The shell will also help you complete path names.
To run a job (program) in the background, type an ampersand (&) at the end of the command line. To suspend the currently running job, press Ctrl-Z. To force a suspended job to run in the background, type bg <job>. To bring a background job into the foreground, type fg <job>. To see a list of jobs currently running (or suspended) type jobs. If you exclude the <job> argument on these commands, it defaults to whatever job was last running in the foreground (not the one currently in the foreground).



Let’s take a look at what file permissions are. *nix O/S are multi-user systems. To protect individuals and their private data, a secure file system had to be implemented. A method had to be devised to protect the users from each other. After all, you could not allow the actions of one user to crash the computer, nor could you allow one user to interfere with the files belonging to another user.



Each file and directory on your system is assigned access rights for the owner of the file, the members of a group of related users, and everybody else. Rights can be assigned to read a file (r), to write a file (w), and to execute a file (x) (i.e., run the file as a program).



To see the permission settings for a file, we can use the ls command as follows:
Command: ls –l filename
Output: -rwxrwxrwx 1 root root size date time file
name



We will concentrate on the first portion of the output i.e. the –rwxrwxrwx string and how to interpret it.
A – in the start specifies that this is a file. A ‘d’ in place specifies a directory.
The next three characters specify the owner rights over the file.
Next three characters specify the group rights the owner belongs to.
Last three specify the rights for all other users on the system.



It is easy to think of the permission settings as a series of bits. Here's how it works:



rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000



rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
--- = 000 in binary = 0
So a setting of 700 means that the file can be read, written and executed by the owner but the group and others are not able to do anything.



The command to change permissions regarding a file is chmod. Here is a sample usage:
Command: chmod 700 some_file


Your Answer

Join or Login to Submit Your Answer

Register Login
   or   




* We'll send an email with a link to activate your account.

We'll publish your answer as soon as you activate your account.