Bash script help needed
How can I make a script do the following:
Script should check the number of arguments given on commandline and if they are less than 2, it should echo a message and exit. I suspect it is easy but I am a newbie in this. Thanks for your help. |
Code:
#!/bin/bash ARGS is arbitrary - you could call the variable anything you wanted (e.g. ralph) then use it throughout the script (e.g. $ralph instead of $ARGS) Note it is important you set the ARGS (or ralph or whatever) variable before doing much else in the script as other things within the script might set their own arguments so you'd get a false count. The [ ] is the same as "test". If you type "man test" you'll see many things you can do with this. Note the use of "-lt" which is "less than". |
Looks suspiciously like homework.
|
@mensawater: Thanks for your help. Can you suggest some good site for learning bash programming.
@grail (senior member): You can check my other posts- I am beyond the homework age but trying to make linux as my main OS. |
Fair enough. I will take you at face value then and suggest the following sites:
http://tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/TitleIndex |
For many things if you do a web search with the item and "tutorial" you'll get lots of good hits.
For example doing a search for Bash Scripting Tutorial came up with one of the links above (which says advanced) and the one below which I'd think would be more tailored to newbies: http://linuxconfig.org/Bash_scripting_Tutorial |
Thanks for the links.
@grail: I appreciate your efforts in encouraging kids to learn themselves. |
The wooledge BashGuide has the best explanation of general scripting concepts I've yet found. linuxcommand.org comes in just behind it in usefulness, due to its more hands-on, by-example, approach.
http://mywiki.wooledge.org/BashGuide http://www.linuxcommand.org/index.php http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/index.html http://www.gnu.org/software/bash/manual/bashref.html http://wiki.bash-hackers.org/start The rest are good references to look at, when you have the time. |
Thanks for the links.
|
All times are GMT -5. The time now is 10:57 AM. |