I'm on a AIX box and need a program that when used after a pipe does nothing.
I'll be more exact. I need something like this:
if [ $NOSORT ] ; then
SORTEXEC="/usr/bin/doesnothing"
else
SORTEXEC="/usr/bin/sort -u"
fi
# BIG WHILE HERE
do
done | SORTEXEC
I tried to use tee > /dev/null
, but I don't know if there is another better option available.
Can anybody help with a more appropriate program then tee
?
Thanks in advance
A pipe in Bash takes the standard output of one process and passes it as standard input into another process. Bash scripts support positional arguments that can be passed in at the command line.
Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes.
To find out if a bash variable is empty: Return true if a bash variable is unset or set to the empty string: if [ -z "$var" ]; Another option: [ -z "$var" ] && echo "Empty" Determine if a bash variable is empty: [[ ! -z "$var" ]] && echo "Not empty" || echo "Empty"
Redirect output to less command using a pipe Output from other commands can be piped to less command to make it easier to scroll along each line at a time.
Use tee
as follows:
somecommand | tee
This just copies stdin to stdout.
Or uUse true
or false
. All they do is exit EXIT_SUCCESS
or EXIT_FAILURE
.
somecommand | true
Notice, every output to stdout from somecommand
is dropped.
Another option is to use cat
:
somecommand | cat
:
is the portable, do-nothing command in the POSIX specification.
if [ "$NOSORT" ] ; then
SORTEXEC=:
else
SORTEXEC="/usr/bin/sort -u"
fi
:
is guaranteed to be a shell built-in in a POSIX-compliant shell; other commands that behave similarly may be external programs that require a new process be started to ignore the output.
However, as tripleee pointed out, strings are meant to hold data, not code. Define a shell function instead:
if [ "$NOSORT" ]; then
SORTEXEC () { : ; }
else
SORTEXEC () { /usr/bin/sort -u; }
fi
while ...; do
...
done | SORTEXEC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With