简体   繁体   中英

what does exclamation mark mean in linux?

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!?

Exclamation mark is for "Not" (like in boolean), -d flag is for folder exists in bash.

So its essentially a condition, that says: "if the folder named 'cc201' does not exist then do something

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 ! , ie

! 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM