How do I get an one liner for this condition?

if [ -f ~/.ssh/config ]
    echo -e "\xE2\x9C\x94 Config file existing"

My attempt:

if [ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing"

marked as duplicate by icarus, G-Man, heemayl, countermode, GAD3R Feb 12 '17 at 10:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • so this is correct? if [ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing" I have to check for the opposite, right? – user3142695 Feb 11 '17 at 11:25
  • 1
    You don't want the if keyword. Normally you use && to connect the 2 commands and do not reverse the condition but using || with a reversed condition is valid. so [ -f ~/.ssh/config ] && echo ... – icarus Feb 11 '17 at 11:32
  • Don't forget that the first word after if is a command (if command; then A; else B; fi) -- that means that [ and [[ are commands. – glenn jackman Feb 11 '17 at 12:53
  • 1
    Please don't edit a question to include its answer — especially not a wrong answer. If your "Update" is not meant to be a proposed answer, explain what it is. – G-Man Feb 11 '17 at 22:17

The most readable way (IMHO) is to use the test utility explicitly:

test -f ~/.ssh/config && echo -e "\xE2\x9C\x94 Config file existing"
  • Yep, or one could just use square brackets. Same thing. – Sergiy Kolodyazhnyy Feb 11 '17 at 14:16

Try this,

if [ -f ~/.ssh/config ]; then echo -e "\xE2\x9C\x94 Config file existing"; fi


[ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing"


[ -f ~/.ssh/config ] && echo -e "\xE2\x9C\x94 Config file existing"

and the else has to come last

[ -f ~/.ssh/config ] && echo -e "\xE2\x9C\x94 Config file existing" || echo -e "\xE2\x9E\x97 No config file"

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