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