LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-15-2012, 06:06 AM   #1
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Rep: Reputation: 1
Executing a Shell Script


hi guys i have a simple question

why when we use . (dot) to execute a shell script in current shell ( . scriptname )we dont need to set executable permission to script
but when we want execute a script like ./script we must set executable perm to the file
??

Last edited by mmhs; 07-15-2012 at 06:21 AM.
 
Old 07-15-2012, 06:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by mmhs View Post
why when we use . (dot) to execute a shell script in current shell ( . scriptname )we dont need to set executable permission to script
This doesn not execute the script, it parses the lines in the file (one at the time). This is done in the current shell (the one you parse the file from).
Quote:
but when we want execute a script like ./script we must set executable perm to file
This executes the script. A new (sub)shell is created in which the script is executed.

For parsing you do not need execute permissions, just read permissions.
 
2 members found this post helpful.
Old 07-15-2012, 08:40 AM   #3
wpeckham
Senior Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,660

Rep: Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584
To reiterate...

Dot '.', in Linux use, can represent several things. In the case of ". script" it is 'sourcing' the script into the current shell. That means it is executed in the current context and any changes to environment variable (PATH, etc) will affect the current session.

Another meaning has to do with file system and path. "." and ".." represent current directory and directory above respectively, when used as path elements. The command ' . ./script ' will source a script in the current folder: useful when the current folder is not in your path and the script might otherwise not be found. The simple "./script" attempts to execute the script in the current folder WITHOUT sourcing it, the more normal case.

There are far better and clearer tutorials and explanations with better examples online, but searching for a period using Google is pretty worthless. Most of the beginning Linux, Unix, and shell (BASH) tutorials cover the subject well, and are easier to find.
 
  


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
different way of executing shell script vaibhavs17 Linux - Newbie 3 07-11-2012 07:11 PM
executing perl script inside shell script scriptme101 Programming 3 04-11-2012 10:30 AM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 08:58 PM
Executing a command in Shell Script gjagadish Programming 7 10-15-2007 05:23 AM
executing a shell script from C llama_meme Programming 2 04-01-2002 10:10 PM


All times are GMT -5. The time now is 11:07 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