Tuesday, July 28, 2009

Unix script help?

im taking a beginner course on UNIX, and i missed the class on scripts


anyway, im lost and have a test moday. so can anyone help me with this


one of the examples is this: write a shell called mult which is executed as ./mult a b, where a and b are integers. the script outputs the product of a and b.


if you could help me id be very appreciative, also if you can explain the process behind it that would be wonderful

Unix script help?
my guess :








#!/bin/sh


expr $1 \* $2








I have no unix around, but that works under linux and SH is what is used under unix according to a site I just visited... so that should work.





don't forget to make the file executable (chmod u+x mult)





the first line indicates it must be interpreted by sh...


on the second line, you have $1 and $2 which are the arguments a and b you pass to mult on prompt...


mult itself is $0 and if you were to have 10 parameters, there would be a $10 and so on


the \* instead of * is because * is a wildcard, you can't use it for multiplying, it is then \* that must be used.


More info/examples about/with the expr command :


http://www.freeos.com/guides/lsst/ch02se...





I'd suggest that you google something like


unix script


that's how you can find some good tutorials (you can also add this keyword (tutorial)) about unix scripting.


IMO, taking a good tutorial or two and practicing a bit probably might worth the course you're taking.





good luck!
Reply:You may contact an unix expert at websites like http://oktutorial.com/


No comments:

Post a Comment