2016-08-09 3 views
1

내 스크립트스크립트가 파일 확장자를 인식하지 못하는 이유는 무엇입니까?

#!/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 

그러나

[email protected]:~/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 

내가

[email protected]:~/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 

내 스크립트에 어떤 문제가 디렉토리 목록 파일을 procmt로 이동? 만약 내가 제대로 이해하고

+2

'./tsmp -ascii i'는'./tsmp -ascii "가 아닙니다. $ i"'; 변수를 전혀 확장하지 않으므로 항상 파일 이름으로'i'를 사용합니다. 'i'는'.ats '로 끝나는 문자열이 아니므로 오류가 있습니다. –

답변

5

이 당신을 위해 작동합니다 : 당신이 .ats 파일에만 관심이있을 때 모든 파일을 반복 할 필요가 없습니다

dest='/home/milenko/procmt' 

cp *.ats "$dest" 

cd "$dest" 

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

. mycd 함수는 cd 일 뿐이므로이를 피할 수 있습니다.

+3

Might'|| CD를'/ home/milenko/procmt '에 넣지 않으면'./tsmp' 명령을 실행하려고하지 않을 것입니다. 어떤 이유로 든. –

+1

@anubhava 네, 맞습니다. –

+1

@CharlesDuffy : 네, 좋은 지적입니다 만, 사용자가 주어진 경로에 대한 권한 문제를 가지고 있다면'cp '가 실패하기 전에'cd'가 실패 할 것이라고 생각합니다. – anubhava

관련 문제