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.
执行 bash shell 脚本时,谁能帮我在文件中添加 2 行。当我们下次运行相同的脚本时,它不应该从下一次开始将相同的行添加到文件中。
要在文件中添加行,您可以在 shell 脚本中使用 echo 语句。在您的 shell 脚本中,您需要先检查文件是否存在或创建一个。
TRANSLOG=/tmp/translog.txt if [ -e $TRANSLOG ]; then echo "File translog already exists!" else echo >> $TRANSLOG fi echo -e "line1" > $TRANSLOG; echo -e "line2" > $TRANSLOG;