LinuxQuestions.org
Review your favorite Linux distribution.
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, 05:06 AM   #1
mmhs
Member
 
Registered: Oct 2010
Posts: 101

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 05:21 AM.
 
Old 07-15-2012, 05:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 07:40 AM   #3
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,927

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

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

All times are GMT -5. The time now is 07:38 PM.

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
Open Source Consulting | Domain Registration