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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-15-2012, 05:06 AM
|
#1
|
Member
Registered: Oct 2010
Posts: 101
Rep:
|
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.
|
|
|
07-15-2012, 05:23 AM
|
#2
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Quote:
Originally Posted by mmhs
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.
|
07-15-2012, 07:40 AM
|
#3
|
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
|
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.
|
|
|
All times are GMT -5. The time now is 07:38 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|