開個帖,開始學習shell編程

來源:互聯網
上載者:User

標籤:

恩,就這麼開始了

首先說一下這個小小的插曲。。。寫著寫著,它就崩潰了,然後我也崩潰了。。。崩潰的我到處找一個不會讓我崩潰的工具,然後找來找去就找到了scribefire。

 

1. 關於從Command Line取參數進來

~ Shell Built in Variables ~ Meaning
$# Number of command line arguments.
$? Exit Status
$* string that contains all arguments to shell
[email protected] Same as above, except when quoted.
$- Option supplied to shell
$$ PID of shell
$! PID of last started background process (started with &)

另外,還有$1,$2,$3...代表低N個參數。

 

2. 關於方括弧

這貨是一個函數!它不是符號!不是符號!它等同於test命令,那個吧,你要是不給它整個空格啥的,等著報錯吧,解譯器會告訴你找不到符號啊啊啊。

#!/bin/sh##Script to test if..elif...elseif [ $# -eq 0 ]thenecho "$0 : You must give one integers!"exit 1fiif [ $1 -gt 0 ]then        echo "$1 is positive"elif [ $1 -lt 0 ]then        echo "$1 is negative"elif [ $1 -eq 0 ]then        echo "$1 -eq 0"else        echo "Opps! $1 is not number, give number please!"fi
千萬記得`[`後面要加空格,`]`前面也要空格啊啊啊。
3. 
有事先放一下:
source
http://linux.vbird.org/linux_server/0250simple_firewall.php
http://tille.garrels.be/training/bash/
http://freeos.com/guides/lsst/index.html
http://www.hlevkin.com/Shell_progr/hellobash.htm
http://www.cyberciti.biz/faq/bash-for-loop/
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.ibm.com/developerworks/linux/library/l-bash/index.html

開個帖,開始學習shell編程

相關文章

聯繫我們

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