You can find more about [
by typing man [
into the terminal. This is a test construct for use after if
, etc. Hence,
-z STRING
the length of STRING is zero
-e FILE
FILE exists
! EXPRESSION
EXPRESSION is false
-d FILE
FILE exists and is a directory
1) [ -z "$(which ssh)" ]
means test if "$(which ssh)"
is a zero-length string. $(...)
means to execute the ...
part first. If you run which ssh
in a terminal, you'll see that it will produce the path to the shh
executable, if it exists. Hence, if this exists, then the string will not be zero-length, and the test will fail.
2) ~
is a shortcut for your home directory, usually located at /home/your_user_name
. [ -e filename ]
means test if this file exists, and return true if it does.
3) [ ! -d ~/.ssh ]
means test if ~/.ssh
(probably /home/your_user_name/.ssh
) exists and is a directory, and if it is not, then return true.
==EDIT==
You should try and sort out the man problem, because it'll really advance your bash knowledge. If man [
doesn't work, try man test
instead. (test
is a synonym for [...]
.) If not, here is an online version.
-w FILE
FILE exists and write permission is granted
I actually think you might have it the wrong way around. It should be
[ -w "$1" ]
not
[ "$1" -w ]