Learning to write shell scripts - linux

1. vim to jump to the first line and last line

Kubigyo: gg
tailing: shift + g

2. shell in how to use expect

Use command interaction can expect

  1. Use can expect in the #! / Bin / bash the head shell file
  2. Using the format:
expect - c " 
spawn 命令
expect{
 \" 预期得到的句子 \"  {send \“ 输入你想输入的话或者响应命令\r\”}
}
expect eof"

3. shell to determine whether a file exists

https://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html

#shell判断文件夹是否存在

#如果文件夹不存在,创建文件夹
if [ ! -d "/myfolder" ]; then
  mkdir /myfolder
fi

#shell判断文件,目录是否存在或者具有权限


folder="/var/www/"
file="/var/www/log"

# -x 参数判断 $folder 是否存在并且是否具有可执行权限
if [ ! -x "$folder"]; then
  mkdir "$folder"
fi

# -d 参数判断 $folder 是否存在
if [ ! -d "$folder"]; then
  mkdir "$folder"
fi

# -f 参数判断 $file 是否存在
if [ ! -f "$file" ]; then
  touch "$file"
fi

# -n 判断一个变量是否有值
if [ ! -n "$var" ]; then
  echo "$var is empty"
  exit 0
fi

# 判断两个变量是否相等
if [ "$var1" = "$var2" ]; then
  echo '$var1 eq $var2'
else
  echo '$var1 not eq $var2'
fi

4. shell used in the system commands

https://blog.csdn.net/zxc024000/article/details/77911770

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/shaoye_csdn1/article/details/93711205