微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linux-为什么脚本无法识别文件扩展名?

我的剧本

#!/bin/bash

cp *.ats /home/milenko/procmt

mycd() {
  cd /home/milenko/procmt
}

mycd

EXT=ats
for i in *; do
    if [ "${i}" != "${i%.${EXT}}" ];then
        ./tsmp -ascii i
    fi
done

milenko@milenko-HP-Compaq-6830s:~/Serra do Mel/MT06/meas_2016-07-13_20-22-00$bash k1.sh


./tsmp: handling 1 files ************************************** total input channels: 1
the name of your file does not end with ats ... might crash soon

main (no rda) -> can not open i for input, exit


./tsmp: handling 1 files ************************************** total input channels: 1
the name of your file does not end with ats ... might crash soon

main (no rda) -> can not open i for input, exit

当我转到procmt目录并列出文件

milenko@milenko-HP-Compaq-6830s:~/procmt$ls *.ats
262_V01_C00_R000_TEx_BL_2048H.ats  262_V01_C00_R086_TEx_BL_4096H.ats  262_V01_C02_R000_THx_BL_2048H.ats
262_V01_C00_R000_TEx_BL_4096H.ats  262_V01_C01_R000_TEy_BL_2048H.ats  262_V01_C03_R000_THy_BL_2048H.ats

我的脚本有什么问题?

解决方法:

如果我正确理解,这应该对您有用:

dest='/home/milenko/procmt'

cp *.ats "$dest"

cd "$dest"

for i in *.ats; do
     ./tsmp -ascii "$i"
done

当您只对.ats文件感兴趣时,无需遍历所有文件.您的mycd函数只是在执行cd,因此您也可以避免这种情况.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐