Linux shell Command Study Notes (1)

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.