Read about interactive shell script tutorial, The latest news, videos, and discussion topics about interactive shell script tutorial from alibabacloud.com
"$passwd \ r"
Exp_continue
}
"*es/no"? * "{
Send "yes\r"
Exp_continue
}
Timeout {
Puts "Connect is timeout"
Exit 3
}
}
Note that the first line is important, usually the first line in our script is #!/bin/bash, and here is the path to the expect program on your machine, which explains that the script is interpreted by expect and not executed by bash, so the syntax of the code and the
;/dev/nullecho\ "$?\" $$Because the ID of the process is unique, it is impossible to have a repetitive PID at the same time. Sometimes the script will need to generate temporary files to store the necessary data. This script may also be used by users at the same time. In this case, the fixed file name is not reliable in the wording. Only dynamic file names can be generated to meet the needs. Symbolic $$ may
A matter of note1. The beginning of a script behavior:#!/bin/bashdeclare the name of the shell that this script requires2. "#!" is out of the program Other than the one that starts with # is the comment content3. For the use of the system command, you can set the primary environment variables such as path at the beginning of the program4. How to run the
the interpreter's _start Begins execution, and the text file is passed to the interpreter as a command-line argument. Therefore, executing the above script is equivalent to executing the program!
After you enter a command to execute a shell script:
1. The interactive process (the parent process) creates a child proc
Turn from: The world of the Intelligence ReporterThis article combines a number of examples to illustrate how to write a shell script.Why Shell ProgrammingIn Linux systems, although there are a variety of graphical interface tools, sell is still a very flexible tool. The shell is not just a collection of commands, but also a great programming language. You can au
First, the Shell function
All scripts so far in this tutorial have been executed from beginning to end. This is good, but you may have noticed that some of the script segments are duplicated.
The shell allows a set of command sets or statements to be formed into a usable block called a
Linux Shell Scripting Basics Here we first talk about the shell's grammatical basis, beginning, annotation, variables and environment variables, to do a basic introduction, although not involved in specific things, but lay a good foundation for later learning easy premise.1. Linux Scripting BasicsBasic Introduction to 1.1 grammar1.1.1 StartThe program must start with the following line (must be on the first line of the file):#!/bin/shThe symbolic #! i
must start with the following line (the first line of the file must be placed ):
Code:#! /Bin/sh
Symbol #! The program used to tell the system to execute the script. This example uses/bin/sh. The script has been edited. to execute this script, you must make it executable:
Code:Chmod + x filename
Enter./filename to execute the script.NoteIn the
command > file redirects the output to file.Command redirects the input to file.command >> file redirects the output to file in an append manner.n > file redirects the file descriptor n files to filename.n >> files redirect files with file descriptor N as an append to file.N > m merges the output file m and N.N Note: File descriptor 0 is typically standard input (STDIN), 1 is standard output (STDOUT), and 2 is the standard error output (STDERR).Output redirection
Execute com
Linux Shell script automatically modifies the IP address and the ip address of the linuxshell script
As a LinuxSA, scripts are used in routine O M, while static ip addresses or MAC binding are used for server ip addresses. Of course, the latter operations are relatively cumbersome, in the former, we can set the host name, ip address information, gateway, and oth
Basics of Linux Shell scripting here we first talk about the shell of the basic syntax, the beginning, comments, variables and environment variables, to do a basic introduction, although not related to specific things, but lay the foundation is to learn easily after the premise.
1. Linux Scripting Basics
1.1 Syntax Basic Introduction 1.1.1 The beginning of the program must start with the following line (mus
Scripting is essential for Linux testing, and the name of the shell script can be arbitrarily defined, and no suffix, such as the name can be written abc,smartzip, as long as the runtime typeThe./smartzip will be able to run the script.Do not use spaces at the beginning of each command line.Part 1th. Basics of writing Linux scripts1.1 Basic Introduction to grammar1.1.1 OpeningThe program must start with the
Use here documentation
Copy Code code as follows:
#!/bin/sh
FTP-IVN 210.29.28.124 User Yun yun2011
Lcd/home/veyun
Cd/home/veyun/yhb
Get V
Bye
Eof
Explain:
-I: Turns off interactive prompts during multiple file transfers, so there's no hint that users can enter user names and passwords
-N: Automatic logon When initial connection is blocked
-V: Set the FTP command to verbose mode so that you can see the commands in the session
specific response. For example, the following chat script waits for the standard output to show login: String, then sends somebody as the user name, then waits for Password: prompt, and sends a response to sillyme.Login: Somebody password: sillymeThis script is used to implement a logon process and use a specific user name and password for logon.The simplest script
Tags: file external shell Script programming intermediate run Info GPO Language POS1. Like other languages, the shell can also contain external scripts, which makes it easy to encapsulate some common code as a standalone fileExample: The testshellfileinclude.sh script is as follows:the #!/bin/Bash#
The printf command is used to format the output and is an enhanced version of the echo command. It is a finite variant of the C-language printf () library function, and is somewhat different in syntax.Note: printf is defined by the POSIX standard, and portability is better than echo.As with the echo command, the printf command can also output a simple string:
$printf "Hello, Shell\ n"
Hello, Shell
Why shell programming?
In Linux, although there are a variety of graphical interface tools, ghost is still a very flexible tool. Shell is not only a collection of commands, but also a very good programming language. You can use shell to automate a large number of tasks. Shell is especially good at system management tas
Document directory
Variable assignment and reference
If sentence
| Operator
Case statement
Select statement ============================================== =
While/for Loop
Quotation marks
Binary to decimal conversion
Circular file copy
Original article: http://www.ha97.com/2619.html
We can use any text editor, such as gedit, kedit, emacs, VI, to write shell scripts. It must start with the following line (the first line of the file must
=/etc/sysconfig/network
dir=/data/backup/' Date +%y%m%d '
netmask=255.255.255.0
echo "================================================"
Echo
#定义change_ip函数
function Change_ip ()
{
#判断备份目录是否存在, there are spaces before and after the brackets! The exclamation point in the shell means the opposite.
If
[!-D $DIR];then
Mkdir-p $DIR
Fi
echo "Now change IP address, doing Backup Interface eth0"
CP $ETHCONF $DIR
grep "DHCP" $ETHCONF
#如下 $? Used
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.