Write to file, but overwrite it if it exists

前端 未结 8 1574
一个人的身影
一个人的身影 2020-12-07 07:29
echo \"text\" >> \'Users/Name/Desktop/TheAccount.txt\'

How do I make it so it creates the file if it doesn\'t exist, but overwrites it if it

8条回答
  •  温柔的废话
    2020-12-07 08:26

    Despite NylonSmile's answer, which is "sort of" correct.. I was unable to overwrite files, in this manner..

    echo "i know about Pipes, girlfriend" > thatAnswer

    zsh: file exists: thatAnswer

    to solve my issues.. I had to use... >!, á la..

    [[ $FORCE_IT == 'YES' ]] && echo "$@" >! "$X" || echo "$@" > "$X"
    

    Obviously, be careful with this...

提交回复
热议问题