将命令应用于特定文件

时间:2014-12-07 15:30:42

标签: bash

我正在尝试创建一个bash脚本,该脚本从用户处获取命令并将其应用于特定类型的文件中。 有人可以提供代码。

echo "Enter your command"
read user-cm
echo "Enter the type of files (ex. php, c, )"
read filetp
find . -name "*. $filetp" -type f  | xargs $user-cm

好吧我发现只需将user-cm的变量名更改为某个(mycm)并将xargs更改为“$ mycm”

echo "Enter your command"
read mycm
echo "Enter the type of files (ex. php, c, )"
read filetp
find  -name "*."$filetp"" -type f  | xargs "$mycm"

1 个答案:

答案 0 :(得分:1)

只需进行一些更正:

echo "Enter your command"
read user_cm
echo "Enter the type of files (ex. php, c, )"
read filetp
find . -name "*.$filetp" -type f  | xargs $user_cm

搜索名称中有空格,变量名称中不允许-

当事情'不起作用'时,请仔细检查错误信息,它们一般都很重要。

相关问题