linux指令碼學習

來源:互聯網
上載者:User

進入當前指令碼所在目錄(其他神馬方法都是浮雲!)
SH_DIR=
x=`echo $0 | grep "^/"`
if test "${x}"; then
        SH_DIR=$(dirname $0)
else
        SH_DIR=$(dirname `pwd`/$0)
fi
cd $SH_DIR

指令碼暫停
bash -c 'read -n1 -p "Press any key to continue..." '

顯示指令碼的命令:(預設是off)
set -v 顯示命令
set +v 關閉顯示命令的選項

讀取設定檔:
假設有個text.txt內容如下:
test=2 #這是一個測試.

$ vi text.sh

#! /bin/shvalue=4value=$(cat test.txt | grep test= | head -1 | awk -F '=' '{print $2}' | awk -F '#' '{print $1}')echo ${value}
$(xx)是取xx命令的傳回值. ${xx}是取xx變數.

printf "xx\n\tyy\n" 比echo好用,可以自己控制換行

echo "xx" > log.txt 寫到文本
echo "xx2" >> log.txt 追加到文本尾

linux指令碼編程(shell)簡介:http://blog.csdn.net/compiler_hdz/article/details/575113 (寫的很完備了,不過是針對bash得)
Dash與Bash的文法區別:http://www.igigo.net/archives/169
linux shell邏輯運算子、邏輯運算式詳解:http://www.cnblogs.com/chengmo/archive/2010/10/01/1839942.html
linux awk 命令說明:http://blog.csdn.net/tianlesoftware/article/details/6278273

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.