5.1.6 Command interpreter (Shell) - scripts

 Back  Linux  Next

The command interpreter is not just a 'window' that provides an environment for the terminal-emulator and assignment of available commands, but something much more than that. Debian uses the default BASH (GNU Bourne-Again SHell), which is essentially the executable file size of 600 kB, which is located in the directory [/bin].

 voda:~# cd /bin
 voda:/bin# ls -al | grep bash
 -rwxr-xr-x  1 root root 700492 2008-05-12 21:02 bash
 lrwxrwxrwx  1 root root      4 2010-04-18 11:42 rbash -> bash
 lrwxrwxrwx  1 root root      4 2010-04-18 11:42 sh -> bash

BASH is a SH-compatible command interpreter, it operates in an environment called SHELL which execute commands received on standard input or from a file. In itself contains useful features 'Korn' and 'C' command interpreters (shell 'ksh' and 'csh'). SH is the original UNIX shell, also known by the name of 'Bourne Shell' by name the programmer who had designed. Other two shells contain a host of powerful features that the original does not have SH shell, part of which was implemented in the BASH shell. From one shell may call for another shell, and a third of it, and so in the series. Current shell works in previously activated. It has already been stated that the interruption of the execution of commands performed with a key combination <CTRL> + <C>, while the output of neighboring shells made with a key combination <CTRL> + <D>. Output from the first used shells in a row means also opt out of the system.

Size of 'bash' shell in kB suggests that the file has quite content. Generally, each shell including this one, has built (built-in) commands, which by activating shells continuously available to the user, the shell can be invoked to execute any executable file or script from [/bin], [/sbin], [/usr/bin] or [/etc] directory. According to this concept any command in directories [/bin], [/sbin] and [/usr/bin] can be seen as external command (DOS-like) and can therefore be executed from any shell. Shell of in the work relies on its associated libraries, which means that the installation of additional shells involves installing their respective content (executable files, configuration files, libraries, documentation ...) in multiple directories.

Commands built into the shell

It has already been stated that Linux is case sensitive, and the default command ' su ' recognizes a command ' SU ' is not recognized because it is not any. Almost all commands have a name with a lowercase. The same holds true for embedded commands (built-in) in the shell of which keyword (KW) by major listed hereinafter:

Specific expressions, logical and mathematical operators of shell

In addition to built-in commands are used and specific terms, some kind of command, which is not generally used alone but rather some kind of loop counting or testing. Course operators are used to set could be enforced, and it is understood that are not capitalized.

Stated reminiscent of keywords and operators, programming languages, and how they are used, and when creating the script, making sure the script for the programmers to be much easier than a user who is a novice in this area.

Keyboard shortcuts

Keyboard shortcuts can greatly speed up the work on the computer, and it is therefore useful to know. Important for the command line is that all along the typed text using the arrow keys ' left ' and ' right ' can move the cursor along the lines inscribed. In this sense, helping key combinations to quickly perform some actions. A smaller portion of these stands is shown on.

As for the Windows operating systems and is very true, if installed graphical interface - GUI to speed to the computer realizes the simultaneous use of keyboard and mouse. If it is a server that does not have a GUI installed, the importance of knowing 'keyboard shortcut' is even greater. Specific program support, as ' pico ' editor, with TUI interface will have their 'keyboard shortcuts', which is again useful to learn.

The sequence of commands that are executed under the supervision of the shell is called SCRIPT. In this way, we can automate many complex tasks. The directory [/etc/] is also a series of scripts that are executed during start-up and shutdown, or during the actual operation. Most of them are in [/etc/init.d] directory and [etc/rcX.d] directories. So, they are used when you want to stop or start a service if it is stopped or just reboot (restart), such as 'DNS' or 'apache2' service by example for the [/etc] contents, in order to accept the entered configuration changes without any need to take the computer off and then turns back physically or hot (reboot). A skilled user will write a script for all tasks that require a lot of time. Below are a few simple examples.

Example V

Script to delete obsolete electronic mail older than 40 days, which lazy user is not deleted.

 #! /bin/zsh
 cd /var/mail
 for i in *
  mail-expire --delete 40 $i
  chown $i:mail $i
  chmod 660 $i

Each script in its first line has a record that indicates in which shell are to be executed. If no shell listed as ' zsh ' in this example, it should be installed on the system or write a script for another shell. The above indicates that the script can be executed from the shell without any transition from one shell to another.

Example VI

Script to create a list of infected e-mail message to a specific date.

 #! /bin/bash
 echo "Statistic of viruses, enter the date"
 read d
 grep "$d" /var/log/mail/mail.info | grep INFECTED | cut -d " " -f 8 |
           tr -d ",()" | sort | uniq -c | sort -nr

Writing the script makes a lot of sense. Thus, for example, polished server configuration files can be saved on a stick, to be reset after reinstalling the server with a simple script that will copy them to stick at the proper place. Restart the computer reads the new configuration file with the settings that the administrator wanted. Quickly and efficiently, without the use of a multitude of copy editors and textual content. On the contrary, can copy to stick all of the original configuration and then 'burn' a CD about archiving.


But not everything is so good and easy, all previously stated only the tip of the 'iceberg' called Linux. There's a lot under the surface: regular expressions, e.g. programming in GNU C compiler, Perl, Python, and more, let's say for the specific use of the web service as PHP (Hypertext Preprocessor - scripting language for creating dynamic web content) and MySQL (relational databases) is becoming the rule, which again is a huge part of reading. Specifically for the master to use Linux commands on a server without the fear of possible damage and take advantage of all that is offered, it should at least take a good books from the Internet in PDF format and is constantly reading :-). Just a lifelong education!?

Debian is a multi-processing and multi-user system, and other than the user ' root ' and as ' drago ' in the system can exist is still a lot of users, especially when it comes to server. Each of them has the right to the use of software installed. But that would not interfere in one another their personal preferences for program support that are commonly used in the directory [/home/USER_NAME/]. In that there are deviations so as unread mail users kept in file [/var/mail/user_name]. It is possible for users to determine their needs and other locations, or whether it will define itself when using the client software by the user. For specific applications users should consult system administrator.


 Content - Home
 Content  Informatics Alphabet
Citing this page:
Radic, Drago. " IT - Informatics Alphabet " Split-Croatia.
{Date of access}. <http://www.informatics.buzdo.com/>.
Copyright © by Drago Radic. All rights reserved. | Disclaimer