shell scripts in OS X

Posted:
in Genius Bar edited January 2014
Could any of you Unix gurus tell me how to write a shell scripts in OS X. I've tried using pico to create a text file, but I can't get it to execute. I added "#!/bin/tcsh" to the file, but it still won't run. Any help would be appreciated.

Comments

  • Reply 1 of 8
    You also probably need to chmod the file to be executable.
  • Reply 2 of 8
    kecksykecksy Posts: 1,002member
    [quote]Originally posted by Brad:

    <strong>You also probably need to chmod the file to be executable.</strong><hr></blockquote>



    I've tried using chmod +x, but it doesn't seem to work.
  • Reply 3 of 8
    What does "won't run" mean?



    How about telling us the error you get.
  • Reply 4 of 8
    thuh freakthuh freak Posts: 2,664member
    should go something like this:

    1. write the script in a file, "myscript"

    2. `chmod +x myscript` (on cli)

    3. `./myscript` or `&lt;insert correct shell here&gt; myscript` (on cli)
  • Reply 5 of 8
    kecksykecksy Posts: 1,002member
    thanks for step 3. I didn't know the "./" was required. That wasn't in the instructions I was using for writing scripts.
  • Reply 6 of 8
    [quote]Originally posted by Kecksy:

    <strong>thanks for step 3. I didn't know the "./" was required. That wasn't in the instructions I was using for writing scripts. </strong><hr></blockquote>



    The use of ./ is only needed if your environments PATH variable does not contain it.
  • Reply 7 of 8
    stimulistimuli Posts: 564member
    So, in other words, if your script "blah.sh" is in /bin/ (/bin/blah) then merely typing: blah will execute it. If it is in /some/directory/blah (ie: not in your $PATH of executable commands) then ./blah or /path/to/blah will do the trick.



    Shell scripts are k-rad! I use one to sync the latest PPC linux kernel additions, then recompile the kernel (using my backed up .config), make the modules, install them, move the kernel to my Mac HFS partition, name it the date (ie: vmlinux-2002-10-09), and pop up a window (using xmessage on X) saying everything went spiffy, reboot to use the new kernel. All w/ one command.
  • Reply 8 of 8
    kecksykecksy Posts: 1,002member
    Thanks for the help and "./" explanation. I appreciate it.
Sign In or Register to comment.