#!/bin/bash
#sh j
find . -name "*first*" && echo "file found" || echo "file not found"
read -p "Run command $foo? [yn]" answer
case "$answer" in
y*) find . -type f -exec rename 's/(.*)\/(.*)first(.*)/$1\/beginning_$2changed$3/' {} + ;;
n*) echo "not renamed" ;;
esac
fi
我希望脚本循环遍历文件夹和子文件夹,并查找包含某些字符串的文件,然后可以选择重命名文件或选择它(即是y / n选项),然后脚本应继续查找。
我也有一个问题,说“语法错误意外令牌'fi'”
试试这个:
#bin/bash
handle_file(){
local file=$0
local pattern=some_pattern
if [[ $(grep -c ${pattern} ${file}) -gt 0 ]];
then
......................................
do anything you want with your ${file}
......................................
fi
}
export -f handle_file
find . -type f -exec bash -c 'handle_file "$@"' {} \;
handle_file
是一个将作为调用的函数handle_function <filename>
,因此<filename>
可以$0
在该函数内部使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句