Linux Shell Command Learning notes (i)

Source: Internet
Author: User

To get the server IP shell script:

The code is as follows Copy Code

#!/bin/bash
Ifconfig | grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' |cut-d:-f2 | awk ' {print '} '

Download Whole Station


WGET-MK http://www.111cn.net

Judge the existence of a file

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"];d o
echo "Sorry try Again"
Read passwd
Done

For statement

The code is as follows Copy Code
#! /bin/bash
For i in a b C; Todo
echo "$in"
Done

Case statement

  code is as follows copy code


#!/bin/ SH
echo "Enter a number"
Read number
Case $number in
        1)
&nb sp;       echo "You are 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.