Zsh Mailing List Archive
Messages sorted by:
Re: echo "true" > ~/.zshrc from ~/.zshrc
- X-seq: zsh-users 21654
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: echo "true" > ~/.zshrc from ~/.zshrc
- Date: Sat, 11 Jun 2016 11:05:01 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=0+n3uXB73t+9I0ZqydXJ1fOzTQ1IVjLJIddE96tLm8g=; b=lj99n/ZY5XIckmgBl3ICWBnHlWVmXqtyQLVeWdU1y1jIxLNAl4qXIgWXjBKOnyw8ZQ JVAN73N9S4pRZeo/M5NR23C1hjScgpfNd1tu07XZN9zEakcRlVIHThOYF8Rwr4gIKOfY CWDExQ5LEgRu3VpRY6rwT3WtM8YXwiIN11deKmLxMrNmeoN1qLRLAI5Mq2diDaTTnSJO pTZ3mJoRoNXRZDcf8hHk7xLqCV8djLb/vXjTEaYuuXGhTa7wjhiH0wreD0Wn+H2w1iwn A3/Yd6z530Y4wTWRPuAlyrCQ1ptzUoVOpL5dTxNXxskm1XJjd2VSreTKq40r8jwAgEXu Qa8g==
- In-reply-to: <CAKc7PVBsCerq5-qAG21De2fQq53MNFOOShjTYQV6eS5stBCGpQ@mail.gmail.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVBsCerq5-qAG21De2fQq53MNFOOShjTYQV6eS5stBCGpQ@mail.gmail.com>
On Jun 11, 6:23pm, Sebastian Gniazdowski wrote:
} How legal it is to do:
} echo "true" > ~/.zshrc
} From ~/.zshrc? What can be expected?
See my earlier mention of how scripts are executed line by line as they
are read. If you truncate ~/.zshrc this way, then the only parts of it
that will be executed are the parts that were already slurped into the
operating system I/O buffer before the file was truncated.
If you truncate the file and then write more bytes to it than had fit
in the I/O buffer (or more than were in the file in the first place),
then when the buffer is next filled (at some indeterminate future read
by the zsh parser) you're likely to get just part of what you wrote,
i.e., the tail after skipping the number of bytes that were previously
Or you might just get an I/O error of some kind, it depends on the OS.
Further, if you truncate and write FEWER bytes than previously read,
you may end up with a file that has a whole bunch of NUL ('\0') butes
at the end to pad it out to the size it had before you tried to write
it while it was still being read. This used to happen a lot with NFS
This isn't zsh specific, this can happen with any file that is written
while another process is reading it. It's a bit more likely to do odd
things if the SAME process is doing both the reading and the writing,
though, which is the situation you've created.
If you want to do this kind of thing, write to a new file and then
rename it to ~/.zshrc to avoid opening the same file twice.
Messages sorted by: