From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18546 invoked by alias); 11 Jun 2016 18:04:49 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21654 Received: (qmail 18622 invoked from network); 11 Jun 2016 18:04:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=0+n3uXB73t+9I0ZqydXJ1fOzTQ1IVjLJIddE96tLm8g=; b=DA7EzvfXuVNygpgKSrcZ5Xu0NrCn6COkQfiSlX5YM9oL6hBAI7RTXSvl1NPPtkKn1l vqm/yxlQC78ssBuIneok9sQt8TMj2tE4s9MQuTBdYqGiuI1RfPRaPZ7tMPyZC64j0YhN 1xcKm2HlLM0DLq033CwM5w9t5JwqKNeo1Bj4a1SJdOzErzysmeGLU2HnETJVE3H6vBMl vheFCYiF1k0k0kFXXxeY0kylG/DVKKdQZzUpzjhVvXIpxMzgvBWFwwLLCiCxY22Bwh5b vlsiNEaus6kMgjMKzypqNilSEkXTEHq86E/lUnMvnoWZDxWip8EKU5v6ecFNHcLhvqw3 2pnA== X-Gm-Message-State: ALyK8tIBmj5MOwy7mjMRSJmzBWBTvcb8DT7zgKPWcTRk91lm1SlmfOVXAVw9uuj10xyzMQ== X-Received: by 10.98.79.90 with SMTP id d87mr9706799pfb.120.1465668287274; Sat, 11 Jun 2016 11:04:47 -0700 (PDT) From: Bart Schaefer Message-Id: <160611110501.ZM12996@torch.brasslantern.com> Date: Sat, 11 Jun 2016 11:05:01 -0700 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "echo "true" > ~/.zshrc from ~/.zshrc" (Jun 11, 6:23pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: echo "true" > ~/.zshrc from ~/.zshrc MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 buffered. 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 filesystems. 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.