|
#1
| |||
| |||
| basic script question.
Very newbie question sry but here goes:- What format do i have to save a script file as and how do i run a script from terminal? cheers. |
|
#2
| |||
| |||
|
Shell scripts (like Bash) are just text files. You will have to set the permissions to give yourself execute access (Use the chmod command). Also when you execute your script be sure that the script is store in a directory on your search list or if the script is in you current directory use the ./ path before the scriptname (or add the ./ directory to your search list).
|
| The Following User Says Thank You to xserve@home For This Useful Post: | ||
n1cster (March 24th, 2009) | ||
|
#3
| ||||
| ||||
|
Another thing to watch out for is the line break format. Scripts must use Unix-style line feeds (LF). Script-oriented text editors like TextWrangler let you easily see and change the line break style.
|
| The Following User Says Thank You to Mikuro For This Useful Post: | ||
n1cster (March 24th, 2009) | ||
|
#4
| ||||
| ||||
|
Although you can usually run a script by typing a "./" before the script name, you can also run it by passing it as an argument to the shell. Like 'bash scriptname.sh'.
|
| The Following User Says Thank You to fintler For This Useful Post: | ||
n1cster (April 2nd, 2009) | ||
|
#5
| |||
| |||
|
Fintler: True. What you are doing then is spawning a new process ("bash"), just to run a script. And sometime there are good reasons for doing so. In the olden days, it would have seemed unnecessary overhead. Fast computers today -- poof! |
| The Following User Says Thank You to xserve@home For This Useful Post: | ||
n1cster (April 2nd, 2009) | ||
|
#6
| |||
| |||
|
About "format". Generally shell scripts start with line #!/bin/sh The #! is called shebang (for some reason), and it means to kernel that - the file is a script - the script is interpreted by program that is after the shebang You run the script either - by giving its name: name-of-the-script - by giving its path : /dir/subdir/name-of-the-script - by giving source command to your current shell (either . or source, depending on the shell you are using) The first case works only if the script is on place named in $PATH environment file. The first and second case work only if you have set the execution bit on the file (using command "chmod u+x the-file-name"). But, if you meant the extension by the shell script, there is no restriction, but normally the script is named either without extension ("myfinescript") or with extension that reminds that it is shell script ("myanotherscript.sh") |
| The Following User Says Thank You to artov For This Useful Post: | ||
n1cster (April 2nd, 2009) | ||
|
#7
| ||||
| ||||
| Actually, it's called "hash-bang." The "#" is called "hash," and the "!" is called "bang." Sometimes people shorten it to "she-bang."
__________________ Mac mini 2.0GHz 10.6.2 • 4GB • 320GB • Superdrive • 4 x 1TB USB 2.0 • LED Cinema Display MacBook 2.0GHz Core 2 Duo - White 10.6.2 • 4GB • 250GB • CD-RW/DVD-ROM iPhone 3G 8GB • iPod Touch 8GB • iPod Photo 60GB • iPod nano 1GB • AT&T U-Verse 18Mb/2Mb http://www.jeffhoppe.com |
| The Following User Says Thank You to ElDiabloConCaca For This Useful Post: | ||
n1cster (April 2nd, 2009) | ||
![]() |
| Bookmarks |
| Thread Tools | |
|
|