George OLson said the following on 11/09/2011 09:25 PM:
I am trying to set up ssh, and I find different command line examples on the internet to help in my research. As I am learning CLI and scripting, can someone explain the following to me please?
In a given directory, I typed in the following line.
if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi
It created the file authorized_keys and gave it the time stamp and changed the permission. I got that part.
The only thing I don't understand is the very first boolean clause after the "if".
What exactly does the exclamation mark signify?
MAN(1) Test says ! EXPRESSION EXPRESSION is false and -f FILE FILE exists and is a regular file Why "test"? Well at the start of the man page it also says SYNOPSIS test EXPRESSION test [ EXPRESSION ] How did I get there? Well the man page for the BASH shell says CONDITIONAL EXPRESSIONS Conditional expressions are used by the [[ compound command and the test and [ builtin commands to test file attributes and perform string and arithmetic comparisons. Expressions are formed from the following unary or binary primaries. And it goes to repeat what you can find in the TEST man page. Its nice to have TEST as a shell built in. When we got that it really improved performance over the old Bourne shell which had to fork off a process to do the test.
What also is the "-f" option?
WTF? Knowing the right man page is useful. Of course I cheat, I use 'apropos' a few times and don't expect to get the right answer the first time. -- In preparing for battle I have always found that plans are useless, but planning is indispensable. Dwight D. Eisenhower -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org