In my script to compile my program in XCode, I need to change the config file from
<string>${NAME}</string>
to <string>My New Name</string>
And after finish, redo this changes. So this line work:
cat $PLIST | sed "s/\${NAME}/${NEW_NAME}/" > $PLIST
--> Build my program
cat $PLIST | sed "s/${NEW_NAME}/\${NAME}/" > $PLIST
But, sometime my file $PLIST
is empty! And I don't know why. Is this a file protection? How can I force the file to be write?
Sounds like maybe a race condition.
cat
is trying to read the file, but your I/O redirection clobbers it. Sometimes it gets clobbered first and you get an empty file. If you're using GNUsed
you can use the-i
flag to change the file in place. Otherwise, you should probably use a temporary file.Ex (GNU):
or