How do I get an one liner for this condition?
if [ -f ~/.ssh/config ]
then
echo -e "\xE2\x9C\x94 Config file existing"
fi
My attempt:
if [ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing"
How do I get an one liner for this condition?
if [ -f ~/.ssh/config ]
then
echo -e "\xE2\x9C\x94 Config file existing"
fi
My attempt:
if [ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing"
Try this,
if [ -f ~/.ssh/config ]; then echo -e "\xE2\x9C\x94 Config file existing"; fi
or
[ ! -f ~/.ssh/config ] || echo -e "\xE2\x9C\x94 Config file existing"
or
[ -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"
The most readable way (IMHO) is to use the test
utility explicitly:
test -f ~/.ssh/config && echo -e "\xE2\x9C\x94 Config file existing"
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:25if
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:32if
is a command (if command; then A; else B; fi
) -- that means that[
and[[
are commands. – glenn jackman Feb 11 '17 at 12:53