当前位置:网站首页>Shell script

Shell script

2022-06-24 21:06:00 AcTarjan

Variable

NAME=$ID					# Will parse variables ID
NAME=AcTarjan				#$NAME=AcTarjan
NAME=hello world			# Will make mistakes , No spaces 
NAME="$ID world"			# Variables are parsed 
NAME="hello world"			# Spaces are allowed 
NAME='$ID world'			# Variables will not be resolved ,$ID Original output 
NAME=`pwd`					# The variable is equal to the result of the command execution output 

Regular expressions

Common operations

  • Determine whether the directory exists
if [ ! -d $INSTALL_DIR ]; then
    echo "$INSTALL_DIR doesn't exist"
    exit
fi
  • Judge whether the file exists
if [ -f "/data/filename" ];then
  echo " File exists "
else
  echo " file does not exist "
fi

  • string matching
# regular expression 
if [[ $FILENAME =~ ^test.*zip$ ]];then
    echo "matched $FILENAME"
else
    echo "mismatched $FILENAME"
fi
  • Traverse the directory
for file in `ls`
do
	echo $file
done
原网站

版权声明
本文为[AcTarjan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211319438401.html