echo Something >> SomeFile
I want this append to work only if
SomeFile exists already.
Right now I am using the following:
if [ -e SomeFile ]; then echo Something >> SomeFile fi;
But there should be a race condition here. During the if condition evaluation
SomeFile may exist. A context switch happens between the if condition and the append. Some other application executes that removes
SomeFile. In that case the append would create
I need to solution to work for both bsd sed and gnu sed.
$ rm SomeFile $ python -c "import os; print(os.open(\"SomeFile\",os.O_APPEND))" Traceback (most recent call last): File "<string>", line 1, in <module> OSError: [Errno 2] No such file or directory: 'SomeFile' $ touch SomeFile $ python -c "import os; print(os.open(\"SomeFile\",os.O_APPEND))" 3