I want to know if there is a built-in BASH command that prints some text on stderr, just like the echo command that prints text on stdout. I don’t want to use temporary io-redirection. I use a built-in command to generate an error on stderr such as ls --asdf (ls: unrecognized option ‘–asdf’) but I want something neater.
Edit —-
Actually I am trying to demonstrate stderr/stdout redirection, and my example looks like:
sh test.sh >test-out.txt 2>test-err.txt
For clarity, I want to keep the test.sh file as simple and clean as possible, this means avoiding > operator inside the file.
echo something >&2is the correct way to do what you want.However…
This will create a little program that will echo its arguments to
stderr:You can use it like this: