Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to know if there is any man page documenting the construction of the most basic script commands like if/then/else, while, for each, and all the relative switches, like -eq, -e, -ge, and so on.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

You have to look at the manual for the specific shell you are using as the exact syntax for using these constructs can vary between shells. Most likely you are using bash, so you would do man bash. Although there are many cases where you might be using something else. For example many distros use a POSIX shell for boot scripts (eg Debian uses dash) or a least use bash in POSIX compliant mode. Usually you can do man sh to get the documentation in this case (this will be linked to the man page for the shell used if it is not the original sh or Bourne shell).

If you are unsure which shell you are using, see this question - determine shell in script during runtime

Another thing work mentioning is the help builtin for bash, it gives an abbreviated version of what is in the manual for the various builtin commands/flow control statements etc. You can use help on its own to see a full list of what is available, otherwise you can try things like help if, help for, help test and help [.

share|improve this answer
    
+1 for mentioning help. Note that [ is simply an alias of test, and is not part of conditional statement syntax. –  nyuszika7h Mar 5 at 15:15
    
This. help is pretty much what I needed. –  ludiegu Mar 6 at 10:44
    
@nyuszika7h, yup, that's exactly what help [ says! –  Graeme Mar 6 at 10:55

Have a look at the man page for the shell you're using. For bash, the flow control statements are documented under 'SHELL GRAMMAR' -> 'Compound Commands'.

share|improve this answer

These are builtins of the shell you are using. So, man bash or equivalent for your shell. Particularly for bash, the man page is not too long and a very good read. Go through it and you will have a much better feeling what's possible and how stuff works (at least you know it exists for future reference).

share|improve this answer
3  
builtins usually refers to commands that are built into the shell as opposed to executed from files in the filesystem, not to keywords in the shell syntax like if/then/else. –  Stéphane Chazelas Mar 5 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.