The shell adds a line of content at the end of the file (the content is a variable)

#Add a new line gg at the end of the /opt/b.txt file

str='gg'
sed -i '$a\'$str /opt/b.txt

--Note: There must be content in the file, and it cannot be empty, otherwise the command will be executed, although no error will be reported, but a new line cannot be added and the file content is empty.

 

Guess you like

Origin blog.csdn.net/yabignshi/article/details/114364672