# !/bin/bash
echo '[] 使用校验字符串、文件,2种使用的方式: ①[] && [] ②[ -a ]'
if [ -n "not empty string" ] && [ -n "not empty string also" ]
then
echo "true"
fi
if [ -n "not empty string" -a -n "not empty string also" ]
then
echo "true"
fi
echo '[[]] 使用校验字符串、文件,2种使用的方式: ①[[]] && [[]] ②[[ && ]]'
if [[ -n "not empty string" ]] && [[ -n "not empty string also" ]]
then
echo "true"
fi
if [[ -n "not empty string" && -n "not empty string also" ]]
then
echo "true"
fi
echo "数字的判断 、小数bc"
if [[ 12 -gt 10 ]]
then
echo "12>10"
else
echo "12 not 大于 10"
fi
#数值字符串比较
#if [[ $(echo "12.12>12.1201" | bc) = 1 ]]
#数值比较
if [[ `echo "12.12>12.1201" | bc` -eq 1 ]]
then
echo "12.12>12.1201"
else
echo "12.12 not 大于 12.1201"
fi
linux shell脚本 字符串、整数、小数判断
于 2022-09-09 17:04:01 首次发布