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.
<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.
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.
Comments
<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.
How about telling us the error you get.
1. write the script in a file, "myscript"
2. `chmod +x myscript` (on cli)
3. `./myscript` or `<insert correct shell here> myscript` (on cli)
<strong>thanks for step 3. I didn't know the "./" was required. That wasn't in the instructions I was using for writing scripts.
The use of ./ is only needed if your environments PATH variable does not contain it.
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.