1. 程式人生 > >【shell指令碼學習-3】

【shell指令碼學習-3】

part-1:

 

#!/bin/bash
#source,sh,./shell_name :shell指令碼執行方法
#

#變數
#declare :修飾
x=10/2
echo "$x"
#將變數修飾為只讀
declare -r x
x="a" #再次為變數賦值檢驗修飾
echo "$x"
#將變數修飾為只為整數
declare -i x
x=10
echo "$x"
#typeset <=> declare
y=8/2
echo "$y"
typeset -i y
y="b"
echo "$y"

 

 

 

 


#x=1;
#w=9;
#let "x+1"
#echo "$x"
#y="$(x+w)";
#z="a";
#echo "$x $y $z";

 

:<<cat
Alias rm="rm -i"

#./home/user_name,/etc/profile,/etc/bashrc 使用者shell的配置檔案
more shells #shell的種類
echo "$SHELL '當前shell的版本是' $BASH_VERSION" #列印當前使用shell型別
echo "hello world"
echo "$?" #shell退出狀態碼<0-255>
abc
echo "$?"
#exit 120
#echo "$?"
cat

:<<ftp #多行註釋
echo "$#" #返回傳入引數的個數 #單行註釋
echo "

[email protected]"
echo "$0" #返回當前指令碼的名稱
echo "$_"
echo "$*" #分別列出引數


echo "$x"
wile getopt ":pq:"y:
do
case $y in
"p")
echo "$y";;
"q")
echo "$x $y";;
"::")
echo "$x";;
"?")
echo "$x
"*")
echo "z";;";;
esac
echo "w"
done
#for i in `ls .`
#do
# if echo "$i" | grep "a"
# then
# echo "$i"
# fi
#done
ftp

 

 

 

#!/bin/bash
#關於引號 "" ,'',``

:<<FTP
echo "開始你的程式"
read "$z"
echo "當前所在的目錄是 `pwd` and 你主機的地址是 `ifconfig`"
echo "程式結束"
FTP

#全域性和區域性變數

#定義一個函式
func(){
echo "$x" #輸出這個全域性變數
}
x="hello world" #定義一個全域性變數
func


func(){
y=1 #在函式內部定義變數
}
func
echo "$y"

#呼叫定義的函式