나는 많은 .html 파일들로 이루어진 myDir
디렉토리를 가지고 있습니다. 배열의 색인을 생성하고 디렉토리의 특정 html 파일을 참조 할 수 있도록 디렉토리에있는 모든 파일의 배열을 만들려고합니다. 나는 다음 줄 시도 :bash 스크립트는 디렉토리에있는 모든 파일의 배열을 만듭니다.
myFileNames=$(ls ~/myDir)
for file in $myFileNames;
#do something
을하지만 난 카운터 변수를 가질 수 있기를 원하고 다음과 같은 논리가 :
while $counter>=0;
#do something to myFileNames[counter]
내가 쉘 스크립팅 아주 새로운 오전에 드릴 수 없습니다를 이를 달성하는 방법을 알아 내면이 문제와 관련하여 도움을 얻을 수 있습니다. 또한 배열의 반복에 대해이 작업을 수행 할 수 있습니다
# create an array with all the filer/dir inside ~/myDir
arr=(~/myDir/*)
# iterate through array using a counter
for ((i=0; i<${#arr[@]}; i++)); do
#do something to each element of array
echo "${arr[$i]}"
done
:
가능한 복제 (http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array 대신 while 루프를 사용하는 루프를 사용하여) – miken32