I made a script for updating IPv4 of MyDNS.JP with a shell script (MyDNS.jp-v4-Update.sh). , Note the findings at that time
Substitute without opening a space
hoge="hoge"
If you open a space and substitute as shown below, you will get angry with not found
or command not found
.
hoge = "hoge"
It seems that it can be taken as a numerical value
${#hoge}
Put a dollar on your head
echo $hoge
ʻEcho" Moji $ {hoge} Moji "`
Enclose in backticks
hoge=`echo "hoge"`
Enclose in $ ()
. Easy to write when nesting
hoge=$(echo "hoge")
For example, the content of ip_res will be something like " 127.0.0.1 200 "
ip_res=
echo """$(curl inet-ip.info/ip -s -m 10 -w ' %{http_code}')"""
## Get date
`` hoge_date=`date "+%Y/%m/%d %H:%M:%S"` ``
## if statement
```sh
hoge="hoge"
if [ ${hoge} = "hoge" ]; then
#Honyara
elif [ 1 -eq 1 ]; then
#Are comparison operators different for numbers and strings?
else
#Funyara
fi
There seems to be no concept of scope unless explicitly specified
fuga() {
#Fugarara
}
fuga
Add the -e
option
echo -e "\n"
-Operators used in if and while statements in shell scripts (bash) -Note on Bash variable scope
Recommended Posts