LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What makes a startup script? (https://www.linuxquestions.org/questions/linux-newbie-8/what-makes-a-startup-script-823844/)

snydergc 08-03-2010 10:12 AM

What makes a startup script?
 
So I know that a script (startup or not) is no more than a DOS batch file. What I don't know is what makes it different from any other file. In DOS of course .bat makes the batch file different. So what is the key to making the file?

GrapefruiTgirl 08-03-2010 10:16 AM

A startup script is the same as any other script, as you pointed out.
("script" being a "shell script", or a series of shell commands, simply put into a file).

The key to the script being identified as a script is what's called a shebang. The shebang is the first line of a script, and its purpose is to define what interpreter shall be used to read and execute the script.

Other than the shebang, a shell script is just a text file. And, you can get away without the shebang if you like, and execute a simple text file by calling using your shell or desired interpreter.

Does this answer the question?

snydergc 08-03-2010 10:43 AM

Thanks, this answers mostly what I wanted. So if I make up a text file of commands and save this file. Will it run the commands when I type in the name of the file and hit return?

GrapefruiTgirl 08-03-2010 10:56 AM

Basically, yes. There are two common ways to execute a shell script:
Code:

shell$ ./filename

or

shell$ sh filename

The former executes a script in the current directory, and depends on the shebang to determine if another interpreter should be used besides the shell you are using to execute the script. The latter indicates that you want to execute the script specifically using the 'sh' interpreter, which is usually a symlink pointing to Bash shell.

If you wrote a perl script, you might execute it like:
Code:

shell$ perl filename
Note that using the ./ method requires that the scripts execute bit be set (make the script executable), while the 'sh' method will execute a script even if it isn't set executable.

snydergc 08-03-2010 11:08 AM

Thanks, now it is clear.

GrapefruiTgirl 08-03-2010 11:12 AM

Great! :) Unless you wind up with some more questions about this, you may mark this thread [SOLVED] if you wish, using "Thread Tools" above the first post.

Cheers, and happy scripting!


All times are GMT -5. The time now is 09:28 AM.