我的剧本:
#!/bin/bash for file in *.ats; do if [[ ("${file}" = THx) || ("${file}" = THy)]] then cp $file /home/milenko/procmt fi done
目录中的文件
262_V01_C00_R000_TEx_BL_128H.ats 262_V01_C01_R000_TEy_BL_128H.ats 262_V01_C02_R000_THx_BL_128H.ats 262_V01_C03_R000_THy_BL_128H.ats
使用
extglob进行扩展通配怎么样?这样您就可以使用for本身来获取所需的扩展:
原文链接:https://www.f2er.com/bash/384152.htmlshopt -s extglob for file in *TH?(x|y)*.ats; do # do things with "$file" ... done
* TH?(x | y)*.ats扩展为包含< something>的文件TH x或y< something> .ats
您的脚本失败,因为您有一个拼写错误:
if [[ ("${file}" = THx) || ("${file}" = THy)]] # ^ # missing space
这可以:
$d="hi" $[[ ($d == hi) || ($d == ha) ]] && echo "yes" yes
虽然括号是多余的:
$[[ $d == hi || $d == ha ]] && echo "yes" yes