I have been going through some online courses on that they asked me to clone a repository from GitHub as follows...
Clone the git repository that contains the artifacts needed for this lab, if it doesn't already exist.
[ ! -d 'cc201' ] && git clone https://gitlab.com/ibm/skills-network/courses/cc201.git
But, I don't understand the below command
[ ! -d 'cc201' ]
what's the use of this?? Can anyone know what exactly does it used for!?
Note that ! does not have a special meaning in Linux (the operating system), but in several standard programs in Linux. In your case it is not so much a feature of bash (as Mark Bramnik claimed in his otherwise correct answer), but of the standard program called test or [. Since bash emulates this command internally, of course it has to interpret the ! as well, but the definition can be found by doing a man test, where it is described as:
! EXPRESSION EXPRESSION is false
Actually, bash does have a ! too, with a related, but not identical meaning. If you invoke a program by prefix it with !, i.e.
! prog
bash sets the exit code to 0 if prog terminated with a non-zero exit code, and sets it to 1 if prog terminated with exit code zero. Therefore, you could have written
[ ! -d cc201 ]
equally well as
! [ -d cc201 ]
The overall effect is the same, but the former is the ! from test, which in turn in emulated by bash, while the latter is the builtin ststus-code negator of bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With