Artificial intelligent assistant

Echo to file descriptor overwrites the file? I am having trouble understanding what is happening when I try to write to a file descriptor? It appears to be overwriting the original contents? Is this expected behaviour? I have replicated this in the example below: $ echo "The quick brown fox ..." > example.txt $ echo "The quick brown fox ..." >> example.txt $ cat example.txt The quick brown fox ... The quick brown fox ... $ exec 88<>example.txt $ cat example.txt The quick brown fox ... The quick brown fox ... $ echo "jumped" >&88 $ cat example.txt jumped ck brown fox ... The quick brown fox ... $ echo "jumped" >&88 $ cat example.txt jumped jumped n fox ... The quick brown fox ...

Because you hadn't done any reads on descriptor 88, the current seek position was "0", and so the write took place at that point.

If, instead, you'd read the file before then, then appends happen:


bash-4.2$ cat <&88
The quick brown fox ...
The quick brown fox ...

bash-4.2$ echo hello >&88

bash-4.2$ cat example.txt
The quick brown fox ...
The quick brown fox ...
hello

bash-4.2$ echo more >&88

bash-4.2$ cat example.txt
The quick brown fox ...
The quick brown fox ...
hello
more

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 5e0be908efe24f27a1d885c8e0d8cc15