Created
April 14, 2015 05:16
-
-
Save Code-Hex/4e0caae24644b6abbe16 to your computer and use it in GitHub Desktop.
初めてのshellscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| a=1 # Space 無しで書く | |
| b=2 | |
| c=`expr $a + $b` | |
| echo c = $c # 変数の中身を見る時には $ マークを使う | |
| d=`expr $a - $b` | |
| e=`expr $b / $a` | |
| f=`expr $a \* $b` # かけ算は気をつける | |
| g=`expr $a % $b` | |
| echo d = $d | |
| echo e = $e | |
| echo f = $f | |
| echo g = $g | |
| echo Hello!! $c $d | |
| str1=This\ is\ example # 空白はバックスラッシュを使う | |
| echo $str1 | |
| str2="My name is Shell!!" | |
| echo $str2 | |
| echo ${str2}.txt #どこまでが変数名か分かりやすくする {}(ブレス)を使う | |
| echo "--------for-------" | |
| numlist="1 2 3 4 5" | |
| for val in $numlist; do | |
| echo val = $val | |
| done | |
| end=10 | |
| for val2 in $(seq 1 ${end}); do | |
| echo "Now range num : $val2" | |
| done | |
| for i in {1..20}; do | |
| echo $i | |
| done | |
| echo "------------------" | |
| echo "\n--------i f-------" | |
| if [ $1 -eq 3 ]; then # 条件式の中にスペースを書く | |
| echo "This is true!! ${1}!!" | |
| else | |
| echo "Oops, false..." | |
| fi | |
| #三項演算子もどき | |
| [ $# -ne 1 ] && echo "Yes!!" || echo "No!!" # 俺には重要 | |
| str3="fuga" | |
| case $str3 in | |
| hoge) | |
| echo "hoge" | |
| ;; # breakと同じ | |
| fuga) | |
| echo "fuga" | |
| ;; | |
| *) | |
| echo "default" | |
| ;; | |
| esac | |
| echo "------------------\n" | |
| #ヒアドキュメント | |
| python <<TEST | |
| print "This is python" | |
| a=1 | |
| b=5 | |
| while a <= b: | |
| print a | |
| a += 1 | |
| print "Finish" | |
| TEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment