Skip to content

Instantly share code, notes, and snippets.

@externvoid
Last active June 24, 2019 09:10
Show Gist options
  • Select an option

  • Save externvoid/6a036ce033e373fcf615b3fb00d72103 to your computer and use it in GitHub Desktop.

Select an option

Save externvoid/6a036ce033e373fcf615b3fb00d72103 to your computer and use it in GitHub Desktop.
Bash事始め

シェル変数で整数、文字列をあつかう

set -Ceu
i=1
echo $((i * 10)) # => 10
str=OK
str2=NG
str3="Today is the day" #空白を含む文字列
echo $str$str2 # => OKNG
#シェル変数の削除
unset str3

シェル変数で不動小数点、16進数を扱うことができない

bcコマンドを使えば、可能

p=`echo "obase=10;ibase=16;FFFF" | bc`
printf "value is %d" $p # => value is 65535

q=`echo "scale=3;10/3" | bc`
printf "string is %s" $q =>string is 3.333

シェル変数の種類、グローバル、ローカル、変数

local x=1 # 関数内だけで有効
x=1 # global
ar=(1 2 3)
ar[0]=0
echo $ar # => 0
echo ${ar[1]} # => 2

定義済みシェル変数

echo $TIMEOUT # => 空
echo $TMOUT # => 空
echo $HOSTNAME # => MBP15-2016.local

制御構造if, whileとか

test文のオプション

test文のオプション

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment