文件内容:

脚本:
- #!/bin/bash
- source_content="127.0.0.1"
- target_content="helo cloudmusic"
-
- # 指定目录
- directory=`pwd`
-
- # 使用循环遍历目录中的每个文件
- for file in "$directory"/*
- do
- if [ -f "$file" ]; then
- # 使用sed命令替换文件内容
- sed -i "s/$source_content/$target_content/g" "$file"
- echo "已替换文件:$file"
- fi
- done
-
- echo "替换完成"
-
结果:
