help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: redirection to /dev/null


From: Koichi Murase
Subject: Re: redirection to /dev/null
Date: Thu, 10 Sep 2020 09:16:03 +0900

2020-09-10 8:04 Chris Elvidge <celvidge001@gmail.com>:
> I've recently come across a crontab line:
> 0 */6 * * *     /usr/bin/modprobed-db store &> /dev/null

`&>' is an extension to the POSIX shell, and the default setting of
cron doesn't necessarily contain SHELL=/bin/bash.  For example, Ubuntu
by default seems to use /bin/sh (dash) to run crontab.  If you want to
use `&>' in crontab, you need to make it sure that "SHELL=/bin/bash"
is set in the crontab.

> I've also read that '&> /dev/null' is outdated and should be replaced
> with '>/dev/null 2>&1'
>
> True? And exactly why?

I'm also interested in whether it is really outdated and should not be
used.

I can find some discussion on the first item on the page
https://wiki.bash-hackers.org/scripting/obsolete .  The page says that
it is because `&>' has a different unintended meaning in POSIX shell,
but I think the discussion doesn't apply when one consciously writes
Bash scripts (but not POSIX scripts).  If you cannot use any
constructs that have a different meaning in the POSIX shell, you can
never use arithmetic commands `((...))'  for example.

I don't know other sources of the recommendation.  AFAIK, the Bash
manual doesn't mark it as deprecated nor obsolete.  Bash even added a
new variant `&>>' in version 4.0, so I guess they are not considered
outdated by the developer side.

--
Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]