How do I create terminal scripts? [Merged]

Discussion in 'Mac Programming' started by Spanky Deluxe, Apr 24, 2008.

  1. macrumors demi-god

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #1
    I know this is a particular basic question, but how do I create terminal scripts that I can just type in to a terminal window and they'll just execute a few commands? Basically the equivalent to a DOS batch file.

    I know its ridiculously easy but I don't know how to do it!
     
  2. macrumors 604

    MacsRgr8

    Joined:
    Sep 8, 2002
    Location:
    The Netherlands
    #2
    In the Terminal, create a new file: (ignore ">")
    > touch test <ENTER>

    Edit that file:
    > pico test <ENTER>

    Start off by showing it is a shell script:
    > #!/bin/sh
    > "type_your_command_here" (i.e. > say hello)

    Save and exit:
    CTRL-O <ENTER>, CTRL-X <ENTER>

    Now, make it executable:
    > chmod 755 test <ENTER>

    Test it:
    > ./test <ENTER> (if you typed "say hello", your Mac would really say "Hello" to you.

    In the Finder you can put ".command" at the end of "test".
    If you do that, your script will open the Terminal and run it.

    Have fun! :)
     
  3. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    Read up on Bash scripting, another alternative if you want a more Apple style scripting language is to use Applescript.
     
  4. thread starter macrumors demi-god

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #4
    Stupid question: How can I create terminal scripts?

    This is probably a really basic thing for anyone that uses them but how do you create terminal scripts? Basically the equivalent to the old fashioned MS DOS batch file. :confused:
     
  5. macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
  6. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
  7. thread starter macrumors demi-god

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #7
    Cheers. Oh dear, that's embarrassing, I've asked this before! Extra proof at how bad my memory is!! :$
     
  8. macrumors newbie

    Joined:
    Feb 4, 2010

Share This Page