1、脚本中的$处理
#----------------------------------3、copy garbage file-------------------------------
function copy_grabage_file_all()
{
echo "————————————————————拷贝grabage file start———————————————————————————"
index=0
prin='$6'
for host in "${SEAL_HOSTS[@]}"
do
selectindex=`expr $index % $disknum`
sourpath=$(sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no root@${sealmacharr[$selectindex]} "df -h | grep /nvme_ | awk '{printf $prin RS}'|awk 'NR==1'")
destpath=$(sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no root@$host "df -h | grep /nvme_ | awk '{printf $prin RS}'|awk 'NR==1'")
#echo "selectindex:" $selectindex
echo "copy ${sealmacharr[$selectindex]}:$sourpath/ars to $host:$destpath"
scpfile="sshpass -p $PASSWORD scp -o StrictHostKeyChecking=no -r $sourpath/ars root@$host:$destpath"
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no root@${sealmacharr[$selectindex]} "$scpfile"&
index=`expr $index + 1`
done
wait
echo "————————————————————拷贝grabage file end———————————————————————————"
}
$6 需要转义,可以这样定义转义,也可以直接加\转义 \$6
2、shell里以空格分隔字符串失败
sourallhdddisktmp=$(sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no root@$host "lsblk | grep 'hdd_'| awk '{printf \$7 RS}'")分隔失败
加空格替换就成功了
sourallhdddisktmp=$(sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no root@$host "lsblk | grep 'hdd_'| awk '{printf \$7 RS}'")
sourallhdddisk=(${sourallhdddisktmp//\ / })
echo $sourallhdddisk