背景:我在 script_testing 下的单字母目录中有一堆名为 username.sub 的文件名(用户名的第一个字母是文件夹名称)。对于每个 username.sub,我需要检查行 user.$username.contacts 是否存在,如果不存在,则附加该行,后跟一个真正的选项卡。
问题:鉴于我在下面的代码,为什么它没有附加到文件中?我想我错过了一些简单的东西。即使该行不存在,我也会不断收到“已订阅的联系人”。
#!/bin/bash
Path_to_files=/home/user/script_testing/^[A-z]+$/
FULLNAME="${Path_to_files##*/}"
NAME="${FULLNAME%.*}"
if grep 'contacts' $NAME.sub; then
echo 'contacts already subscribed'
else
echo "subscribing to contacts"
echo -e user.$NAME.Contacts \t >> $NAME.sub
fi