Consider the following:
cd /tmp/ echo -e "hello world\nhello world\n:)" >> hello.txt cat hello.txt
hello world hello world :)
bash -c 'sed s/"hello"/"hiiii"/ hello.txt | tee hello.txt' cat hello.txt
hiiii world hiiii world :)
ssh localhost -t 'cd /tmp && sed s/"hello"/"hiiii"/ hello.txt | tee hello.txt' cat hello.txt
Replacing the command with
ssh localhost -t 'cd /tmp && sed s/"hello"/"hiiii"/ hello.txt >> hello.txt'
hello world hello world :) hiiii world hiiii world :)
What about using sed -i to make changes to the file, and not doing any bash redirection?
Alternatively, if the real problem is more complex than that, try using a different name for the output file and rename after it's finished.
Also, as mentioned in a sibling comment, your hello.txt is both an input and output.
Consider the following:
Outputs: Then running yields Reseting to the original `hello.txt` and running yields an empty file.Replacing the command with
yields I'm trying to figure this out so I can publish a script to set up a test env for a package I'm trying to publish, and somewhat stuck on this step...