bash 语法使用
1、定义函数时,不需要使用function作为函数的命名。
函数不需要形参。
函数名不能以数字作为开头
main() { case $1 in 4 ) 1_start ;; 8 ) 1_start 5_start ;; 12 ) 1_start 5_start 9_start ;; * ) echo "请输入参数" ;; esac }
2、bash在进行变量赋值时,"=" 双边不能出现空格
isMount=`mount -a | grep "172.16.0.*"` if [ "$isMount" = "" ]; then mount -o nolock 172.16.0.101:/home /mnt fi cd /mnt/junda/JdLinuxApp/A1627_touchscreen/source/touch_design
:: 计算 MD5 并重命名文件 set "files=%outputAppFileName% %outputHexAppFileName%" for %%F in (%files%) do ( set "filetemp=%%~F" :: 去掉文件路径中的双引号 :: 获取 MD5(排除无关行) set "md5=" for /f "skip=1 tokens=1 delims=" %%A in ('certutil -hashfile "!filetemp!" MD5 ^| findstr /r "^[0-9A-Fa-f]"') do ( if not defined md5 set "md5=%%A" ) :: 去除 MD5 值中的空格 set "md5=!md5: =!" :: 只取前6位 MD5 set "md5_short=!md5:~0,6!" :: 确保 MD5 值正确 if not defined md5 ( echo 错误: 未能计算 "!filetemp!" 的 MD5 值! exit /b ) echo !filetemp! 的 MD5: !md5_short! :: 解析文件名和扩展名 for %%X in ("!filetemp!") do set "filenametemp=%%~nX" & set "ext=%%~xX" :: 生成新文件名(仅用前6位 MD5) set "newfile=!filenametemp!_!md5_short!!ext!" echo !filetemp! -> !newfile! :: 删除已有的同名文件,避免 `rename` 失败 if exist "!newfile!" del "!newfile!" :: 进行重命名 rename "!filetemp!" "!newfile!" )