Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

typecase

macrumors 6502
Original poster
Feb 2, 2005
395
404
Hello,

As one that's new to the Mac, and to the terminal, is there any way to run multiple commands via the terminal. I'd like to run a series of curl commnds and have the next one start once the previous one finishes. For example:

Code:
curl http://www.myhost.com/mydirectory/file.txt -o newname.txt

curl http://www.myhost.com/mydirectory/file2.txt -o newname2.txt

I've tried Applescript via Do script "curl ... " but it doesn't seem to work the way I want it to. In DOS, I'd write a batch file and execute it but I'm not sure what the UNIX or Apple equivalent would be.

Any help greatly appeciated. Thanks.
 
The easiest way is just to add the commands to a file and use "source batchfile"
 
The unix equivalent is called a script too. All you have to do is put all the commands you want into a plain text file, and save it with a name that ends in no suffix (well, technically, that probably doesn't matter). You can use pico to make this at the command line. There are two wrinkles which are unix unique.

After you make the file (say the file is called "curlscript") you must change its permissions so it is executable. You do this with a command called chmod, like this:

chmod 755 curlscript

The 755 is made up of three digits, that represent the permissions for you, others in your "user group" and all others. You want yourself to be able to write to the file and execute it (7) and you want everyone else to be able to read it or execute it but not write it (5). You could also give them 7 if you want (chmod 777 curlscript), etc.

The other wrinkle is that to execute it, you have to always refer to it with its path. If you are in the directory where it is located, you must type:

./curlscript

and not

curlscript.

That's it! :)
 
Wow! Thanks guys! I appreciate the fast response. I've tried both methods and they both work well. I'm loving this operating system more and more everyday! This community's not bad either. :D Thanks again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.