3.6.4 Redirecting Standard Output and Standard Error
http://www.gnu.org/software/bash/manual/bash.html#Redirecting-Standard-O...
#!/bin/bash
# Both are OK:
echo "WARNING! My error message." 1&>2
1&>2 echo "WARNING! My error message."
Note that &>2
is the same as 1&>2
since 1
is stdout and is the default output channel.
Or you could define a function:
#!/bin/bash
print_error() {
echo "$@" 1>&2;
}
print_error "WARNING! My error message."