シェルスクリプト学習帳


MacBookAirのターミナルで複数ターミナルシェルを立ち上げる.
emacsでソースを書いて,もう一つのシェルで実行する仕組み
command+"}"でウィンドウの切り替え
変数,if,case,forの文法事項のおさらい.

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
ソースコード:

#!/bin/sh

echo "veriables ------------------"
PARA1="sample1"    # no space should be inserted around "="
PARA2=sample
echo ${PARA1}
echo ${PARA2}
echo $$            # process ID
echo $@            # list of all the arguments
echo "arg1 = $1"   # designated argumment

echo "if ---------------------------"
if [ $1 -gt $2 ]
then
    echo "$1 is grater than $2"
elif [ $1 -eq $2 ]
then
    echo "$1 is equal to $2"
else
    echo "$1 is smaller than $2"
fi

echo "case --------------------------"
case "$1" in
    "1") echo "$1 is one";;
    *)   echo "default";;
esac

echo "for ---------------------------"
for arg in $@
do
    echo "arg is ${arg}"
done

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

実行結果:
$ ./sample.sh 1 2 3 
veriables ------------------
sample1
sample
453
1 2 3
arg1 = 1
if ---------------------------
1 is smaller than 2
case --------------------------
1 is one
for ---------------------------
arg is 1
arg is 2
arg is 3

このブログの人気の投稿

Callback関数を知らん人がまず理解すべきことのまとめ。

C言語でBluetoothスタックを叩きたい人のBluetooth開発入門その1

C++プログラミング入門(1) // 倉庫番プログラムの実装