This article will introduce my notes on linux. I hope this method will be helpful to you.
Shell script for obtaining the Server IP Address:
| The Code is as follows: |
Copy code |
#! /Bin/bash Ifconfig | grep 'inet addr: '| grep-V' 127. 0.0.1' | cut-d:-f2 | awk '{print $1 }'
|
Download the entire site
Wget-mk http://www.bKjia. c0m
Determine whether a file exists
| The Code is as follows: |
Copy code |
#! /Bin/bash If [! -F/root/log. l] Then echo "log. l note exist" Fi
|
Common syntax
While statement
| The Code is as follows: |
Copy code |
#! /Bin/bash Echo "enter passwd" Read passwd While [$ passwd! = "Iterse"]; do Echo "sorry try again" Read passwd Done |
For statement
| The Code is as follows: |
Copy code |
#! /Bin/bash For I in a B c; do Echo "$ in" Done |
Case statement
| The Code is as follows: |
Copy code |
#! /Bin/sh Echo "Enter a number" Read number Case $ number in 1) Echo "you number is 1" ;; 2) Echo "yo number is 2" ;; *) Exit 1 ;; Esac
|
If else elif fi
| The Code is as follows: |
Copy code |
#! /Bin/sh Echo "Is it morning? Please answer yes or no ." Read YES_OR_NO If ["$ YES_OR_NO" = "yes"]; then Echo "Good morning! " Elif ["$ YES_OR_NO" = "no"]; then Echo "Good afternoon! " Else Echo "Sorry, $ YES_OR_NO not recognized. Enter yes or no ." Exit 1 Fi Exit 0 |