Filenames with wildcards in variables

后端 未结 4 647
孤独总比滥情好
孤独总比滥情好 2021-01-13 02:22
#!/bin/bash
outbound=/home/user/outbound/
putfile=DATA_FILE_PUT_*.CSV
cd $outbound
filecnt=0
for file in $putfile; do let filecnt=filecnt+1; done
echo \"Filecount: \         


        
4条回答
  •  一生所求
    2021-01-13 03:12

    You could test if file exists first

    for file in $putfile; do
      if [ -f "$file" ] ; then
        let filecnt=filecnt+1
      fi
    done
    

    Or look for your files with find

    for file in $(find . -type f -name="$putfile"); do
      let filecnt=filecnt+1
    done
    

    or simply (fixed)

    filecnt=$(find . -type f -name "$putfile" | wc -l); echo $filecnt
    

提交回复
热议问题