This works fine
$ sed -i '' '1i\
my text' $HOME/.bashrc
when there is a line one, but has no effect when there is no line one.
One way, will works in both cases :
{ echo my text; cat file; } | tee file
This work for small files, for big files, use a temporary file :
{ echo my text; cat file; } > temp$$ && mv temp$$ file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.