LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-03-2010, 10:12 AM   #1
snydergc
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Rep: Reputation: 1
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?
 
Old 08-03-2010, 10:16 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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?
 
Old 08-03-2010, 10:43 AM   #3
snydergc
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 1
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?
 
Old 08-03-2010, 10:56 AM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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.
 
Old 08-03-2010, 11:08 AM   #5
snydergc
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 1
Thanks, now it is clear.
 
Old 08-03-2010, 11:12 AM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script via cron makes a empty file szczym Programming 7 09-23-2009 03:58 PM
shell script which makes *something* with every file in folder matt79 Programming 5 02-17-2009 03:58 PM
Script that makes portage on Kanotix 2006 RC3, here maximalred Debian 14 04-03-2006 02:10 AM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 09:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration