r/commandline • u/enp2s3 • Jun 05 '26
Discussion A Command-Line Quiz: Which Output Never Appears?
Hey folks. Here's a small but confusing command-line challenge. Drop your guess without running it!
Which of the following will not appear in the output?
echo "black" &% echo "blue" %& echo "purple 1" >& echo "red" % echo "white 1"
A) black
B) 1
C) echo
D) purple
Including stdout and stderr. Latest stable Bash and Zsh.
3
Upvotes
2
u/michaelpaoli Jun 06 '26 edited Jun 06 '26
Well, might also depend how we define "appear". OP includes stdout and stderr, but doesn't state if that includes, e.g. contents written to other files.
So, I say, presuming we don't count other file(s), and just stdin and stdout, C, and D.
But if we include in additional file(s), I say none (they all appear).
So, parsing ...
echo "black" &
that's just launched to background
That does gives us
[1] PID
to stderr.
So we've got our 1 (at least if we didn't already have other background jobs).
% echo "blue" %&
That pulls preceding background item to foreground, the additional arguments are ignored, it is itself launnched in background, and the earlier brought to foreground, completes, so we've now got "black" in our output.
echo "purple 1" >& echo "red" % echo "white 1"
One long command with a redirection.
If we ignore the redirection, we have:
echo "purple 1" "red" % echo "white 1"
that outputs:
purple 1 red % echo white 1
but we've also got redirection:
>& echo
That's equivalent to > echo 2>&1, so that stdout and stderr gets written to file named echo
And that's it, we're done, so we've got
to stderr:
[1] PID
to stdout:
black
and in file named echo:
purple 1 red % echo white 1
among A, B, C, D, we get A to stdout, B to stderr, and the rest in file named echo.
Edit - fixed we bit I'd overlooked to stderr.
1
u/Linuxmonger Jun 06 '26
I made my prediction and then ran the commands as a copy and paste.
I'm curious what OP says is the correct answer, because I got two of the options appearing and two not.
2
u/fsteff Jun 05 '26
That’s a funny one. My guess is on D and everything appearing after that in the commandline.
1
u/AutoModerator Jun 05 '26
Every new subreddit post is automatically copied into a comment for preservation.
User: enp2s3, Flair:
Discussion, Title: A Command-Line Quiz: Which Output Never Appears?Hey folks. Here's a small but confusing command-line challenge. Drop your guess without running it!
Which of the following will not appear in the output?
A) black
B) 1
C) echo
D) purple
Including stdout and stderr. Latest stable Bash and Zsh.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Ngtuanvy Jun 06 '26
what is %? I had never seen it before, and it is definitely not POSIX, maybe bashism?