Linux Shell Script For Each File in a Directory Grab the filename and execute a program

后端 未结 4 790
耶瑟儿~
耶瑟儿~ 2020-12-07 08:14

Scenario :

A folder in Linux system. I want to loop through every .xls file in a folder.

This folder typically consists of various folders, various filetypes

4条回答
  •  温柔的废话
    2020-12-07 09:19

    for i in *.xls ; do 
      [[ -f "$i" ]] || continue
      xls2csv "$i" "${i%.xls}.csv"
    done
    

    The first line in the do checks if the "matching" file really exists, because in case nothing matches in your for, the do will be executed with "*.xls" as $i. This could be horrible for your xls2csv.

提交回复
热议问题