zsh-users
 help / color / mirror / code / Atom feed
* zsh blocks at file truncation
@ 2013-09-21  7:10 chandan
  2013-09-21  7:46 ` Bart Schaefer
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: chandan @ 2013-09-21  7:10 UTC (permalink / raw)
  To: zsh-users

Hi all,

Like most others I am trying to move from bash to zsh as my default shell.

On zsh, Why does the following block indefinitely?

$ >file.txt

On bash, the above would truncate a file. Also, on bash 'file.txt'
would be created if it does on exist.

After some debugging, I found that the above command blocked at the
invocation of the 'cat' command (as provided by 'ps -c <pid>').

Thanks,
chandan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zsh blocks at file truncation
  2013-09-21  7:10 zsh blocks at file truncation chandan
@ 2013-09-21  7:46 ` Bart Schaefer
  2013-09-21  7:53 ` Phil Pennock
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2013-09-21  7:46 UTC (permalink / raw)
  To: zsh-users

On Sep 21, 12:40pm, chandan wrote:
}
} On zsh, Why does the following block indefinitely?
} 
} $ >file.txt

7.3 Redirections with no command
================================

When a simple command consists of one or more redirection operators and
zero or more parameter assignments, but no command name, zsh can behave
in several ways.

If the parameter NULLCMD is not set or the option CSH_NULLCMD is set,
an error is caused.  This is the `csh' behavior and CSH_NULLCMD is set
by default when emulating `csh'.

If the option SH_NULLCMD is set, the builtin `:' is inserted as a
command with the given redirections.  This is the default when emulating
`sh' or `ksh'.

Otherwise, if the parameter NULLCMD is set, its value will be used as a
command with the given redirections.  If both NULLCMD and READNULLCMD
are set, then the value of the latter will be used instead of that of
the former when the redirection is an input.  The default for NULLCMD
is `cat' and for READNULLCMD is `more'.

-- 
Barton E. Schaefer


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zsh blocks at file truncation
  2013-09-21  7:10 zsh blocks at file truncation chandan
  2013-09-21  7:46 ` Bart Schaefer
@ 2013-09-21  7:53 ` Phil Pennock
  2013-09-25  8:49 ` zzapper
  2013-09-25  9:23 ` Marko Vihoma
  3 siblings, 0 replies; 6+ messages in thread
From: Phil Pennock @ 2013-09-21  7:53 UTC (permalink / raw)
  To: chandan; +Cc: zsh-users

On 2013-09-21 at 12:40 +0530, chandan wrote:
> On zsh, Why does the following block indefinitely?
> 
> $ >file.txt

That's a bare redirection, which means that you're invoking the empty
command.  In bash, that invokes ":", also known as "true".  By
_default_, in zsh, that's "cat" for writing and "more" for reading.

See "REDIRECTIONS WITH NO COMMAND" in zshmisc(1) [or zshall(1)].

So you can either:

    setopt sh_nullcmd

or set:

    NULLCMD=: READNULLCMD=:

to get the behaviour which you're used to.

For myself, I very often invoke:

% >/dev/null

to get a scratch space for fast notes which I don't want to live in
editor swap files, or testing input echo'ing in a terminal without
having a program other than the kernel and the terminal emulator try to
interpret the keystrokes.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zsh blocks at file truncation
  2013-09-21  7:10 zsh blocks at file truncation chandan
  2013-09-21  7:46 ` Bart Schaefer
  2013-09-21  7:53 ` Phil Pennock
@ 2013-09-25  8:49 ` zzapper
  2013-09-25  9:23 ` Marko Vihoma
  3 siblings, 0 replies; 6+ messages in thread
From: zzapper @ 2013-09-25  8:49 UTC (permalink / raw)
  To: zsh-users

chandan <chandanrmail@gmail.com> wrote in
news:12896374.TIKZVcXBhR@localhost.localdomain: 

> Hi all,
> 
> Like most others I am trying to move from bash to zsh as my default
> shell. 
> 
> On zsh, Why does the following block indefinitely?
> 
> $ >file.txt

The syntax for truncation I have is

$ :> bigfile.log

zzapper




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zsh blocks at file truncation
  2013-09-21  7:10 zsh blocks at file truncation chandan
                   ` (2 preceding siblings ...)
  2013-09-25  8:49 ` zzapper
@ 2013-09-25  9:23 ` Marko Vihoma
  2013-09-25 14:54   ` Bart Schaefer
  3 siblings, 1 reply; 6+ messages in thread
From: Marko Vihoma @ 2013-09-25  9:23 UTC (permalink / raw)
  To: zsh-users

Hello,

For a reason unknown with my zsh setup this:

$ > file.txt

creates a new empty file if it does not exist and complains:

zsh: file exists: file.txt

if it exists...

With this:

$ >| file.txt

I can truncate the file and write to it whatever i want like with:

$ cat > file.txt

I must have something setup in my ~/.zshrc for this to work that way, but I'm too lazy to check :D

$ >| file.txt
foo
bar
baz

will end with CTRL-D like with

$ cat > file.txt.

And if I pull what i wrote

$ > file.txt

from history it will give me

$ >| file.txt

Oh dear, what is going on? :D

On Sep 21, 2013, at 10:10 AM, chandan wrote:

> Hi all,
> 
> Like most others I am trying to move from bash to zsh as my default shell.
> 
> On zsh, Why does the following block indefinitely?
> 
> $ >file.txt
> 
> On bash, the above would truncate a file. Also, on bash 'file.txt'
> would be created if it does on exist.
> 
> After some debugging, I found that the above command blocked at the
> invocation of the 'cat' command (as provided by 'ps -c <pid>').
> 
> Thanks,
> chandan
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zsh blocks at file truncation
  2013-09-25  9:23 ` Marko Vihoma
@ 2013-09-25 14:54   ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2013-09-25 14:54 UTC (permalink / raw)
  To: zsh-users

On Sep 25, 12:23pm, Marko Vihoma wrote:
}
} $ > file.txt
} 
} creates a new empty file if it does not exist and complains:
} 
} zsh: file exists: file.txt
} 
} if it exists...

16.2.6 Input/Output
-------------------
...

CLOBBER (+C, ksh: +C) <D>
     Allows `>' redirection to truncate existing files, and `>>' to
     create files.  Otherwise `>!' or `>|' must be used to truncate a
     file, and `>>!' or `>>|' to create a file.

} I must have something setup in my ~/.zshrc for this to work that way

You have not.  NO_CLOBBER (+C) is the default, so setup is needed to
make it NOT work that way.

} And if I pull what i wrote
} from history it will give me
} 
} $ >| file.txt

That's a convenience feature.  The assumption is that if you failed to
create the file because of NO_CLOBBER, but then you go to the trouble
of recalling the history and trying it again, you probably really meant
to clobber the file, so the history fixes that part for you in advance.

This all derives from zsh's distant past as a shell for college students
who had a tendency to accidentally destroy their homework.  Zsh's special
default treatment of "rm *" can be traced to the same thing.  (And I'm
only partly kidding here.)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-25 14:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-21  7:10 zsh blocks at file truncation chandan
2013-09-21  7:46 ` Bart Schaefer
2013-09-21  7:53 ` Phil Pennock
2013-09-25  8:49 ` zzapper
2013-09-25  9:23 ` Marko Vihoma
2013-09-25 14:54   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).