Linux Bash programming

Source: Internet
Author: User

Problems encountered in Bash programming:

First, it is recommended that you write bash under Linux, and if you want to write bash with Windows, you should pay special attention to several issues:

First: Coding problems, encoded with utf-8,

Second: line break problem, Windows is the end of carriage return (CRLF), Linux is the end of line break (LF)

Third: Use Utf-8 without BOM.

These three points are considerations for writing bash under Windows.

As for the grammar, I do not say more on this side, I am also the first to write bash, grammar basically nothing to say, there is a year of programming based on all can understand.

Http://pan.baidu.com/s/1o6C1rnW,


Share a bash clip. This is obtained from the Maven Nexus, and its function is to get the absolute path


# Resolve The true real path without any sym links.
Changed=true
While ["x$changed"! = "X"]
Do
# Change spaces to ': ' So the ' tokens can be parsed.
Safescript= ' echo $SCRIPT | Sed-e ' s;;:; G '
#echo "script path is:[$SCRIPT]"
#echo "Safescript path is:[$SAFESCRIPT]"
# Get The real path to this script, resolving any symbolic links
Tokens= ' echo $SAFESCRIPT | Sed-e ' s;/;; G '
#echo "TOKENS path is:[$TOKENS]"
Realpath=
For C in $TOKENS; Do
# change any ': ' In the token ' back to a space.
C= ' echo $C | Sed-e ' s;:;; G '
Realpath= "$REALPATH/$C"
# If Realpath is a sym link, resolve it. loop for nested links.
While [-H ' $REALPATH "]; Do
ls= "' Ls-ld" $REALPATH "'"
link= "' Expr ' $LS": ' .*-> \ (. *\) $ ' "
If expr "$LINK": '/.* ' >/dev/null; Then
# LINK is absolute.
Realpath= "$LINK"
Else
# LINK is relative.
Realpath= "' DirName" $REALPATH "'" "/$LINK"
Fi
Done
Done


If ["$REALPATH" = "$SCRIPT"]
Then
Changed= ""
Else
script= "$REALPATH"
Fi
Done
# The current directory to the location of the script
CD "' DirName" $REALPATH "'"
Realdir= ' pwd '

Bash Basic Syntax _ download Link: http://yun.baidu.com/share/link?shareid=2510088394&uk=4043945255

A few examples of bash:

1, automatic packaging. Http://pan.baidu.com/s/1bniv5W7

2. The Linux service runs the Java shell. http://yun.baidu.com/share/link?shareid=3338177448&uk=4043945255

3. Linux runs Java commands, including configuration of environment variables, setting of JVM parameters. http://yun.baidu.com/share/link?shareid=3334612191&uk=4043945255

&& Another Windows run Java command, with the same functionality as 3 http://yun.baidu.com/share/link?shareid=3335077510&uk=4043945255


Linux Bash programming

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.