From: Eze on
Greetings! I'm trying for the first time FreeBSD (as a virtual
machine). I invoked /bin/sh but found that stderr redirection does not
seem to happen:

$ givemeanerror >/dev/null 2>&1

prints nothing in Linux, but I get

givemeanerror: not found

in FreeBSD. Does anybody know why? (Ditto if I try givemeanerror 2>&1
>/dev/null.)
From: Andre Majorel on
On 2008-12-20, Eze <garzon.lucero(a)gmail.com> wrote:

> Greetings! I'm trying for the first time FreeBSD (as a virtual
> machine). I invoked /bin/sh but found that stderr redirection
> does not seem to happen:
>
> $ givemeanerror >/dev/null 2>&1
>
> prints nothing in Linux, but I get
>
> givemeanerror: not found
>
> in FreeBSD. Does anybody know why? (Ditto if I try givemeanerror 2>&1
> >/dev/null.)

What is your shell on the FreeBSD host ?

--
Andr� Majorel <URL:http://www.teaser.fr/~amajorel/>
"After 15 minutes, I wanted to marry her. After a half hour, I completely
gave up the idea of snatching her purse." -- _Take the Money and Run_
From: Eze on
The default shell is tcsh, but I deliberately invoked sh, which is
linked to /bin/sh. I assume this is some variant of the Bourne shell,
isn't it? (The man pages are not available.)

On Dec 20, 5:19 pm, Andre Majorel <che...(a)halliburton.com> wrote:
> On 2008-12-20, Eze <garzon.luc...(a)gmail.com> wrote:
>
> > Greetings! I'm trying for the first time FreeBSD (as a virtual
> > machine). I invoked /bin/sh but found that stderr redirection
> > does not seem to happen:
>
> > $ givemeanerror >/dev/null 2>&1
>
> > prints nothing in Linux, but I get
>
> > givemeanerror: not found
>
> > in FreeBSD. Does anybody know why? (Ditto if I try givemeanerror 2>&1
> > >/dev/null.)
>
> What is your shell on the FreeBSD host ?
>
> --
> André Majorel <URL:http://www.teaser.fr/~amajorel/>
> "After 15 minutes, I wanted to marry her. After a half hour, I completely
> gave up the idea of snatching her purse." -- _Take the Money and Run_

From: Sven Mascheck on
Eze wrote:

> $ givemeanerror >/dev/null 2>&1
>
> prints nothing in Linux, but I get
>
> givemeanerror: not found
>
> in FreeBSD.

This redirection is a corner case; usually a redirection
is only referred to the command. But here, most shells
redirect their own output - in case the command could
not be found. (the point might be if the forked child has
its output already redirected when it searches the command)

Grouping is a way to influence it; you will see this:

$ givemeanerror 2>/dev/null
givemeanerror: not found
$ { givemeanerror; } 2>/dev/null
$


I know two shells which need this grouping: the traditional
Bourne shells and the Almquist shell variants (FreeBSD /bin/sh
is such a variant).

As exception, this was changed in dash with release 0.4.7 (dec/02).
If dash had not changed it, it were one of the few properties
to identify an Almquist shell without just eliminating other
possibilities. (Another one is "cmd > file*", which is not
expanded, and which is handled likewise by the traditional
Bourne shell, too).


The time command is another interesting corner case. It is not
a built-in, but usually even part of the grammar; thus you also
need grouping to redirect its output.

Seems difficult to get all this right under all possible
conditions. I just stumbled over the unset error message in
parameter substitution:
{ : ${unsetvar?error}; } 2>/dev/null
bash is confused about where stderr should point to.
The shell doesn't hang, just stderr is lost (and thus the
prompt); hit ctrl-c to fix. It seems to have been fixed
with one of the recent patches, though.


Especially shells have a hard job to behave orthogonally.
From: André Gillibert on
Eze <garzon.lucero(a)gmail.com> wrote:
> The default shell is tcsh, but I deliberately invoked sh, which is
> linked to /bin/sh. I assume this is some variant of the Bourne shell,
> isn't it? (The man pages are not available.)
>

Google and wikipedia helped. It might be a derived from ash.
<http://www.in-ulm.de/~mascheck/various/ash/#freebsd>
<http://en.wikipedia.org/wiki/Almquist_shell> contains:
> Derivatives of ash are installed as the default shell (/bin/sh) on FreeBSD, NetBSD, DragonFly BSD and Minix.
Originally, it was a clone of Bourne shell.

However, you should check that it isn't a simple symbolic link to tcsh.
I installed tcsh and dash (Debian's fork of ash) on my Gentoo system.
tcsh exposes the behavior you've seen, but dash doesn't.
 |  Next  |  Last
Pages: 1 2
Prev: "tr" Command Behaviour
Next: Numeric Keypad in VI