Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 solaris 的 bash 脚本中有以下代码,其中>> (append)不起作用:
>>
for j in $(cat file1.txt); do for i in $(cat file2.txt); do if [ "$j" = "$i" ]; then echo "_$i" >> file3.txt fi done done
不知道为什么file3.txt没有生成
file3.txt
如果您在运行脚本时没有显示错误消息,则>>重定向工作正常。问题是使用它的线路只是碰巧从未被调用过。
只需更换
if [ "$j" = "$i" ]; then
经过
if [ "$j" != "$i" ]; then
确认它(假设两者都不file1.txt为file2.txt空)。
file1.txt
file2.txt