I have a function in my bash that has a sort -h but on one of my setups sort doesn't support the -h flag.
How do I test that so I can provide an else to have a sort without -h?
I have a function in my bash that has a sort -h but on one of my setups sort doesn't support the -h flag.
How do I test that so I can provide an else to have a sort without -h?
You can check the output in a machine with a sort that supports it, and in a machine with a sort that doesn't. Comparing them may help you understand whether they support the option or not.
You can also check the return code of each one, running echo $? after the command. If they differ, you can use that on your favor.
You can check with this if statement.
if (echo | sort -h > /dev/null 2>&1); then echo "yes"; else echo "no"; fi;