I'm opening additional file descriptors in my Bash script with
Reproducer="reproducer.sh"
exec 3<> $Reproducer
This can then be used with e.g. echo
echo "#! /bin/bash" >&3
echo "echo This is a reproducer script." >&3
Source: How do file descriptors work?
As I noticed after lots of tries, the opened file overwrites existing content in the file. If the new content is larger, it will expand the file, but if the new content has less bytes, the old content will remain at the end of the file.
This creates a broken script in my case, because I'm writing a Bash script.
Is there an option to the exec 3<> file
statement to truncate the file while opening?
Alternative solutions:
- delete the file before opening with
rm $Reproducer
.