First, homework (exercise) content:
1. Describe the operation principle of shell program (can be attached with necessary graphic instructions);
What is a shell?
The shell is the interface between the user and the Linux operating system. There are multiple shells in Linux, with bash being used by default. The shell of the Linux system is the shell of the operating system, providing the user with an interface to use the operating system. It is the general designation of command Language, command interpreter and programming language. The shell is a command language interpreter with its own built-in shell command set, and the shell can be called by other applications in the system. Commands entered by the user at the prompt are interpreted by the shell before being passed to the Linux kernel.
For users, there is no need to care whether a command is built inside the shell or a separate program. The shell first checks whether the command is an internal command, or if it is not checked for an application (the application here can be a utility for Linux itself, such as LS and RM, or it can be a commercially available program such as XV, or free software such as Emacs). The shell then looks for these applications in the search path (the search path is a list of directories that can find executable programs). If the command you typed is not an internal command and the executable file is not found in the path, an error message will be displayed. If a command can be successfully found, the internal command or application is decomposed into a system call and passed to the Linux kernel.
650) this.width=650; "src=" Http://images.cnblogs.com/cnblogs_com/mydomain/201108/201108212133269051.png "/>
650) this.width=650; "src=" http://www.2cto.com/uploadfile/2014/0705/20140705111025611.jpg "/>
2, summarize all the knowledge points involved in shell programming (such as: variables, grammar, command status, etc., to take the picture of Yo);
3, summarize the course of all the circular statement, the use of conditional judgment and related examples; (if (jpg|png is not exist); echo "You say a XX")
If [$#-lt 5]; Then
echo "Please enter ' $ remote_ip remote_password remote_dest module Remote_dir '"
Exit 1
Fi
compressjs= "1"
If [$#-ge 7]; Then
$compressjs =$8
Fi
if [! "$JOB _name" = ' King network '];then
if [$COMPRESSJS = = "1"]; Then
For file in ' Find ' $WORKSPACE '-name ' *.js ' | Grep-v '. min.js$ '
Do
/usr/local/bin/uglifyjs $file-o $file-M
echo "Compressed JS file: $file"
Done
Fi
Else
Continue
Fi
#!/bin/bash
#
Declare-i sum=0
Declare-i I=1
While [$i-le 50]; Do
Let sum+= $i
Let i++
Done
echo "Sum: $sum."
#!/bin/bash
#
Declare-i sum=0
Declare-i I=1
Until [$i-GT 50]; Do
Let sum+= $i
Let i++
Done
echo "Sum: $sum."
4. Write a script: If a path does not exist, it is created as a directory; otherwise it is present and the content type is displayed; (Don't doubt it's that simple)
#!/bin/bash
#
If [-Z $];then
echo "Usage:$0 <path>"
Exit 1
Fi
if [!-D $];then
Mkdir-p $
Else
echo "is exists."
File $
Fi
5, write a script to complete the following functions; Judging the given two values, which is the big or small; the method of the given number: script parameter, command interaction; (still so simple using read)
#!/bin/bash
#
Read-p "Please input the other integer:"-T 6 num1 num2
If [-Z ' $num 1 "]; Then
echo "Please input integers."
Exit 1
Fi
If [-Z ' $num 2 "]; Then
echo "Please input integers."
Exit 1
Fi
If [$num 1-gt $num 2]; Then
echo "$num 1 > $num 2"
elif [$num 1-lt $num 2]; Then
echo "$num 1 < $num 2"
Else
echo "$num 2 = $num 1"
Fi
6, the sum of all the odd numbers within 100 (at least 3 methods. Yes, this is our assignment. ^_^)
#!/bin/bash
#
Declare-i sum=0
For I in $ (SEQ 1 2);d O
sum+= $i
Done
echo "Odd sum: $sum."
#!/bin/bash
#
Declare-i sum=0
Declare-i I=1
While [$i-le];d o
If [$[$i%2]-eq 1];then
Let sum+= $i
Fi
Let i++
Done
echo "Odd sum: $sum."
#!/bin/bash
#
Declare-i sum=0
Declare-i I=1
Until [$i-GT];d o
If [$[$i%2]-eq 1];then
Let sum+= $i
Fi
Let i++
Done
echo "Odd sum: $sum."
7, write a script to achieve the following functions:
(1) Pass two text file path to script;
(2) Show the number of blank lines in two files and their blank lines;
(3) Show the total number of files in two files and their total number of rows;
#!/bin/bash
#
Read-p "Please input the text file path:" File1 file2
if [!-F "$file 1"];then
echo "Please input the text file."
Exit 1
Fi
if [!-F "$file 2"];then
echo "Please input the text file."
Exit 1
Fi
If [' grep ' ^$ ' $file 1 | wc-l '-gt ' grep ' ^$ ' $file 2 | wc-l '];then
Ls-l $file 1
Echo ' grep ' ^$ ' $file 1 | Wc-l '
Else
Ls-l $file 2
Echo ' grep ' ^$ ' $file 2 | Wc-l '
Fi
If [' Cat $file 1 | wc-l '-GT ' cat $file 2 | wc-l '];then
Ls-l $file 1
Echo ' Cat $file 1 | Wc-l '
Else
Ls-l $file 2
Echo ' Cat $file 2 | Wc-l '
Fi
8. Write a script
(1) Prompt the user to enter a string;
(2) Judgment:
If the input is quit, exit the script;
Otherwise, the string content of its input is displayed;
#!/bin/bash
#
Read-p "Please input a character string:" str1
If ["$str 1" = = "Quit"];then
Exit
Else
echo "$str 1"
Fi
9, write a script, print 2^n table; n equals the value entered by a user; (Sorry, I'm naughty)
10, write a script, write a few functions: function 1, to achieve the sum of two numeric values, function 2, take a given two numeric value of greatest common divisor, function 3, take a given two numeric value of least common multiple; the selection of the function, two values will be entered through the script parameters.
Second, completion time:
Before September 20, 2015.
Marco Linux+python--2015 Year September 13 course assignment