1

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?

  • What is the output in a machine with a sort that supports it, and in a machine with a sort that doesn't? Also, what is the return code of each one? (you can check that running echo $? after the command) – Valmiky Arquissandas Aug 9 '14 at 14:36
  • @ValmikyArquissandas thanks, that actually answered my question. – laggingreflex Aug 9 '14 at 14:42
  • Well... in that case, I'll leave it as an answer :) – Valmiky Arquissandas Aug 9 '14 at 14:45
1

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.

0

You can check with this if statement.

if (echo | sort -h > /dev/null 2>&1); then echo "yes"; else echo "no"; fi;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.