Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: echo "true" > ~/.zshrc from ~/.zshrc



11.06.2016, 19:24, "Sebastian Gniazdowski" <sgniazdowski@xxxxxxxxx>:
> Hello,
> How legal it is to do:
>
> echo "true" > ~/.zshrc
>
> From ~/.zshrc? What can be expected?
>
> When I do (in ~/.zshrc, at last line):
>
> echo "sleep 200" >> ~/.zshrc
>
> then I'll get the sleep at next startup. When I do:
>
> echo "true" > ~/.zshrc
> echo "Hello normally ended"
>
> Then I will see the "Hello" message.
>
> But when I output much of text earlier in 400 lines long zshrc, then e.g.:
>
> /Users/sgniazdowski/.zshrc:182: command not found: fas
>
> But other time it went without errors, and without "Hello" message.
>
> Best regards,
> Sebastian Gniazdowski

What do you mean by “legal”? If you do something like this you need to understand what is going on: see `man zshmisc`, section “REDIRECTION”. Specifically `>>` appends to zshrc, `>` *empties* zshrc and then appends: nearly equivalent is `rm ~/.zshrc; echo true > ~/.zshrc`.

I personally would not suggest to *ever* edit zshrc using `echo … >[>] ~/.zshrc`: this is a script and using `echo >>` to edit it will over time turn zshrc into an unorganized junkyard. If you need to do some edits, take text editor and edit ~/.zshrc, keeping it organized. This is especially needed if you have many aliases which may alter the subsequent code.



Messages sorted by: Reverse Date, Date, Thread, Author