to use test itself, check for directory presents
Code:
#!/bin/bash
if test -d /usr; then
echo "it is "
else
echo "no it isn't"
fi
your code
Code:
#!/bin/bash
test-f 'Example' && echo Yes
test always checks for true, if it is a truth then it executes, if it is not a truth errors.
both still equate to true, being the executing condition.
if true [directory] do something, else do something else.
if !true [not directory] then do something, else do something else
if directory is there do something is a truth if it is.
if the directory is not there, then that is a truth if it is not there.
Code:
test -d /usr && echo "it is " || echo "no it isn't"
[[ -d /directory ]] && echo "it is there" || echo "it is not there"
as this is a ternary operation, BASH has no true ternary operator.
this here
Code:
userx@SlackOLatern:~/Documents$ touch Example
userx@SlackOLatern:~/Documents$ test -f 'Example' && echo "yes"
yes
userx@SlackOLatern:~/Documents$ test -f 'Example' && echo "no"
no
userx@SlackOLatern:~/Documents$ test -f 'Example' && echo "whatevr you wnat me to do"
whatevr you wnat me to do
is just you telling it to say whatever you want when the condition is true.