Batch execution of commands in Terminal?

Discussion in 'macOS' started by typecase, May 12, 2005.

  1. typecase macrumors regular

    Joined:
    Feb 2, 2005
    #1
    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.
     
  2. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #2
    The easiest way is just to add the commands to a file and use "source batchfile"
     
  3. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #3
    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! :)
     
  4. typecase thread starter macrumors regular

    Joined:
    Feb 2, 2005
    #4
    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.
     

Share This Page