首页 > 解决方案 > 修改几个特定文件中的某些内容,例如 txt (bash)

问题描述

我想在几个文件中写一些东西,我尝试了 find :

find . -name "*.txt" | 

但我不知道在管道之后我能写什么。

我还尝试了“for”:

for element in * 
do
    if [[ $element = '*.txt' ]]
    then
        echo "cc" > $element
    fi
done

但我的如果是错的,

如果有人可以帮助我

标签: bash

解决方案


只需使用带有.txt后缀 in的 glob 模式for

for i in *.txt; do
    # if there are no matching files, break
    [ -f "$i" ] || break
    echo "cc" > "$i"
done

推荐阅读