What are the three formats of conditional statements used in bash scripting?
|
Well, I'm not really sure what the question is asking either, but I think that's not really relevant. As I understand it, the StackExchange take on answering homework-ish questions is that the answers should be generally useful, i.e. should be able to serve as a reference for people who are not just trying to answer a very specific question. The relevant section of the bash manual lists 5 different constructs which can be used for conditional evaluation. Of these, the But they don't mention another very common form used for branching in bash, which is to just execute a command in combination with short-circuit evaluation, for example
This is effectively the same as
but works differently: in the first form, the conditional logic really comes about as a side effect of the actual explicit goal of the code, which is, at least ostensibly, to evaluate the logical operators. This sort of construct is also commonly seen in C and JavaScript code. It works by taking shortcuts: the parts of the expression, e.g. The converse is true for logical ors: So if the To get a feel for the way bash works with conditionals, it's best to do some experimentation on the command line. The command
will echo the return code of the previous statement. This is an error code, so So you can do, for example
and perform similar tests with the As for the answer to your question, well, I think that's very dependent on the context it was asked in. But getting a good understanding of the various options should help you figure out what they are looking for there. |
|||
|