目录中每个文件的Linux Shell脚本获取文件名并执行程序 [英] Linux Shell Script For Each File in a Directory Grab the filename and execute a program
问题描述
场景:
Linux系统中的文件夹.我想遍历文件夹中的每个.xls文件.
A folder in Linux system. I want to loop through every .xls file in a folder.
此文件夹通常由各种文件夹,各种文件类型(.sh,.pl,.csv等)组成.
This folder typically consists of various folders, various filetypes (.sh, .pl,.csv,...).
我要做的就是遍历根目录中的所有文件,并仅对.xls文件执行程序.
All I want to do is loop through all files in the root and execute a program only on .xls files.
问题是我必须执行的程序是将.xls转换为.csv格式的'xls2csv'.因此,对于每个.xls文件,我必须获取文件名并将其附加到.csv.
The problem is the program I have to execute is 'xls2csv' to convert from .xls to .csv format. So, for each .xls file I have to grab the filename and append it to .csv.
例如,我有一个test.xls文件,而xls2csv的参数为:xls2csv test.xls test.csv
For instance, I have a test.xls file and the arguments fro xls2csv are : xls2csv test.xls test.csv
我说得通吗?
推荐答案
重击:
for f in *.xls ; do xls2csv "$f" "${f%.xls}.csv" ; done
这篇关于目录中每个文件的Linux Shell脚本获取文件名并执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!