Linux script Learning

Source: Internet
Author: User

Enter the directory where the current script is located (other methods are cloudification !)
Sh_dir =
X = 'echo $0 | grep "^ /"'
If test "$ {x}"; then
Sh_dir = $ (dirname $0)
Else
Sh_dir = $ (dirname 'pwd'/$0)
Fi
CD $ sh_dir

Script pause
Bash-C 'read-N1-P "press any key to continue ..."'

Command for displaying scripts: (the default value is off)
Set-V display command
Set + V disable the display Command Option

Read the configuration file:
The contents of a text.txt file are as follows:
Test = 2 # This is a test.

$ VI text. Sh

 
#! /Bin/shvalue = 4 value = $ (cat test.txt | grep test = | head-1 | awk-F' = ''{print $2} '| awk-F '# ''{print $1 }') echo $ {value}
 
$ (XX) is the return value of the XX command. $ {XX} is the XX variable.

Printf "XX \ n \ tyy \ n" is easier to use than Echo. You can control the line feed by yourself.

Echo "XX"> log.txt writes to text
Echo "xx2"> log.txt append to the end of the text

Linux Script Programming (Shell) Introduction: http://blog.csdn.net/compiler_hdz/article/details/575113 (write very complete, but for BASH)
Syntax differences between Dash and Bash: http://www.igigo.net/archives/169
Linux Shell logical operators, logical expressions detailed explanation: http://www.cnblogs.com/chengmo/archive/2010/10/01/1839942.html
Linux awk command Description: http://blog.csdn.net/tianlesoftware/article/details/6278273

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.