As true as this can be, it's counterintuitive.
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
What would be more intuitive? It seems to me to be a
a=1 b=a a=2
Where you'd expect b to be 1, which is the case for bash.
What distro uses /Users instead of /home? Doesn't that break the standard?
MacOS
I used macs for 15 years I really should have known that lol.
Playskool
I never use more than one redirection to keep it simple. Stuff gets even weirder when you also use <
in the same lines
envsubst
is a exception.
In bash if you want to redirect both stderr and stdout to file you can use &>filename
.
IMO |& tee dirlist
is easier to manage
Your way would spawn a whole extra process, but if you're running Bash commands I suppose that doesn't often matter.
For 2>&1
to work don't we need to be using some shell anyway?
Yeah. The shell, plus whatever command (or commands) you tell the shell to run.
This is a Bash thing?
https://www.man7.org/linux/man-pages/man1/bash.1.html
Pipelines A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a pipeline is:
[time [-p]] [ ! ] command1 [ [|⎪|&] command2 ... ]
(...) If |& is used, command1's standard error, in addition to its standard output, is connected to command2's standard input through the pipe; it is shorthand for 2>&1 |. This implicit redirection of the standard error to the standard output is performed after any redirections specified by command1.
So it is a bash thing.
Just to be clear, because some seem to conflate Bash with Shell. If not specified, assume POSIX shell, that's how /bin/sh is handled as well. And that has no |&
.
True
But nowadays /bin/sh
is often just a link to bash
Which puts Bash in POSIX compliance mode.
$ sh
sh-5.2$ echo dfgsdfgfd |& tee /tmp/t
dfgsdfgfd
sh-5.2$ cat /tmp/t
dfgsdfgfd
sh-5.2$
¯_(ツ)_/¯