linux bash 編程

來源:互聯網
上載者:User

標籤:linux   linux bash   crlf   

bash 編程中遇到的問題:

首先,建議在linux 下編寫bash,如果你要用windows 編寫bash 的話,那麼,你要特別注意幾個問題:

第一:編碼問題,用utf-8 編碼,

第二:分行符號問題,windows是斷行符號換行(CRLF)結尾,linux 是換行(LF)結尾

第三:使用utf-8無bom。

這三點是在windows 下編寫bash 的注意事項。

至於文法,我這邊就不多做講了,我也是初次編寫bash,文法基本沒啥說的,有一年編程基礎的都能看懂。

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


分享一個bash 片段吧。這是從maven 私服 nexus 中擷取的,其功能就是擷取絕對路徑


# 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
# Change the current directory to the location of the script
cd "`dirname "$REALPATH"`"
REALDIR=`pwd`

bash 基礎文法_下載連結:http://yun.baidu.com/share/link?shareid=2510088394&uk=4043945255

bash 的幾個樣本:

1、自動打包。http://pan.baidu.com/s/1bniv5W7

2、linux 服務運行 java shell。http://yun.baidu.com/share/link?shareid=3338177448&uk=4043945255

3、linux 運行java 命令,包含環境變數的配置,jvm 參數的設定。http://yun.baidu.com/share/link?shareid=3334612191&uk=4043945255

&& 再來個windows 運行java 命令,跟3一樣的功能http://yun.baidu.com/share/link?shareid=3335077510&uk=4043945255


linux bash 編程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.