In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The shell provides you with an interface to UNIX systems. Input collected from you, and execute programs based on that input. When a program finishes executing, it displays the output of that program.
A shell is an environment where we can run our commands, programs, and shell scripts. Shells have different styles, just like operating systems have different styles. Each shell style has its own set of recognized commands and functions.
Shell prompt:
At the prompt, this is what's called the command prompt,$, shell. Although a prompt appears, you can type a command.
shell Read the input and press Enter. It determines the desired command and executes the first character of the input. A word is a complete character set. Spaces and tabs separate words.
Here is a simple example of the date command displaying the current date and time:
$dateThu Jun 25 08:30:19 MST 2009
You can customize your command prompt using the PS1 environment variable explained in the tutorial environment.
Shell type:
There are two main types of shells on UNIX:
Bourne shell. If you are using a Bourne-type shell, the default prompt is the $character.
C shell. If you are using a C shell, the default prompt character %.
There are also various Bourne shell subcategories listed below:
Bourne shell ( sh)
Korn shell ( ksh)
Bourne Again shell ( bash)
POSIX shell ( sh)
The different C-shells are as follows:
C shell ( csh)
TENEX/TOPS C shell ( tcsh)
The original UNIX shell was written in the mid-1970s by Stephen Bourne at AT&T Bell Labs in New Jersey.
The Bourne shell was the first shell to appear on UNIX, hence the name "the shell".
Bourne shell installation is usually/bin/sh on most UNIX versions. For this reason, it is scripted to use in several different versions of the UNIX shell.
In this tutorial, we will cover most of the concepts based on propagating Borne Shell.
Shell script:
The basic concept of shell scripting is that a command list is executed in the order listed. #is a pound sign before shell script comments.
Conditional tests, such as the value A is greater than the value B, loops we go through large amounts of data, reads and stores data files and variables that read and store data, the script may contain functionality.
Shell scripts and functions are explained. This means they will not be compiled.
We will write many scripts in the next few tutorials. This will be a simple text file in which we will put all of our commands and other necessary structures to tell the shell environment what to do and when to do it.
Sample script:
Suppose we create a test.sh script. Note: All script.sh extensions. Adding anything to a script requires alerting the system that a shell script is starting. For example:
#!/ bin/sh
This tells the Bourne shell to execute the following command: This is called home shebang because the "#" symbol is called hash, and! The symbol is called bang.
To create a script that contains these commands, put shebang line first, and then add the command:
#!/ bin/bashpwdlsShell comments:
You can put comments in your script as follows:
#!/ bin/bash# Author : Zara Ali# Copyright (c) Tutorialspoint.com# Script follows here:pwdls
Now save the above so that this script can execute as follows:
$chmod +x test.sh
Now, your shell script can be executed at any time as follows:
$./ test.sh
This would produce following result:
/home/amroodindex.htm unix-basic_utilities.htm unix-directories.htm test.sh unix-communication.htm unix-environment.htm
Note: To execute any program in the current directory, execute using./ program_name
Extended Shell Script:
Shell scripts have several structures necessary to tell the shell environment what to do and when to do it. Of course, most scripts are more complex than that.
Shell, after all, is the real programming language, completing variables, controlling structures, and so on. No matter how complex a script becomes, it is still a list of commands that are executed sequentially.
The following script uses the read command entered from the keyboard, assigns it to the value of the variable PERSON, and finally prints it in stdout.
#!/ bin/sh# Author : Zara Ali# Copyright (c) Tutorialspoint.com# Script follows here:echo "What is your name? "read PERSONecho "Hello, $PERSON"
Here is an example script that runs:
$./ test.shWhat is your name? Zara AliHello, Zara Ali$
Shell variable
A variable is a string, and we assign a value. The assigned value can be a number, text, file name, device, or any other type of data.
A variable is a pointer that does not exceed the actual data. Shell, which can create, assign and delete variables.
Variable Name:
Variable names can contain only letters (a to z or A to Z), numbers (0 to 9), or underscores (_).
By convention, UNIX shell variables will have their names in upper case letters.
The following examples are valid variable names:
_ALITOKEN_AVAR_1VAR_2
The following are examples of invalid variable names:
2_VAR-VARIABLEVAR1-VAR2VAR_A!
Other characters such as!, * cannot be used Or-These characters have special meanings.
Definition of variables:
The variables are defined as follows:
variable_name=variable_value
For example:
NAME="Zara Ali"
The variable name defined in the example above and assigned the value "Zara Ali". This type of variable is called a scalar variable. A scalar variable can hold only one value once.
A shell can store any value you want in a variable. For example:
VAR1="Zara Ali"VAR2=100 Access Value:
To access the value stored in a variable, its name is prefixed with the dollar sign ($):
For example, the following script will access the variable name defined by the value and print it on standard output:
#!/ bin/shNAME="Zara Ali"echo $NAME
This produces the following values:
Zara Ali read-only variable:
The shell provides a read-only command labeled for use with read-only variables. The latter variable is marked read-only and its value cannot be changed.
For example, the following script gives an error prompt while trying to change the NAME value:
#!/ bin/shNAME="Zara Ali"readonly NAMENAME="Qadiri"
This result will produce the following:
/bin/sh: NAME: This variable is read only.
Logged out or deleted variables tell the shell that the list of variables deleted is tracked. Once you unset a variable, you have no access to the value stored in the variable.
Here is the syntax for defining a variable using the unset command:
unset variable_name
The above command unsets the defined variable value. Here is a simple example:
#!/ bin/shNAME="Zara Ali"unset NAMEecho $NAME
The above example will print anything. Variables that cannot be undefined using the unset command are not marked read-only.
Variable type:
When a shell runs, there are three main types of variables:
Local variable: A local variable is a variable that does what the shell in the current instance does. This is not a program that starts with a shell. Set at the command prompt.
Environment variable: An environment variable is a variable that does what is required of any child process shell. Some programs require normal environment variables. Usually a shell script defines that only those programs required for environment variables are not running.
Shell variables: Shell variables are special variables that are set by the shell and are normally required by the shell. Some synthetic variables are environment variables, while others are local variables.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.