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 09-26-2008, 11:37 AM   #1
diego_cn
Member
 
Registered: Mar 2006
Distribution: fedora 7
Posts: 62

Rep: Reputation: 16
need some bash help


I am wondering what's the difference between these 2 ways of calling a script:

Code:
. ./foo.sh
./foo.sh
I remember it has to do with subshell or something like that. But I couldn't find it in the bash reference manual. Any one could point me to the right place please? Thanks.
 
Old 09-26-2008, 11:44 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
I think the first way includes foo.sh (= source foo.sh), the second executes foo.sh
 
Old 09-26-2008, 11:46 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well . is an alias for the source command, which is like a c include. so rather than executing the code in its own process it pulls the code into the current environment. Generally this is more used for library function declarations and variables which would otherwise need to be exported from within the inner bash script once defined.
 
Old 09-26-2008, 03:09 PM   #4
diego_cn
Member
 
Registered: Mar 2006
Distribution: fedora 7
Posts: 62

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by acid_kewpie View Post
well . is an alias for the source command, which is like a c include. so rather than executing the code in its own process it pulls the code into the current environment. Generally this is more used for library function declarations and variables which would otherwise need to be exported from within the inner bash script once defined.
Well explained, I see how it works right now. Thanks.
 
  


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
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
BASH -copy stdin to stdout (replace cat) (bash browser) gnashley Programming 4 07-21-2008 01:14 PM
Bash development - move chmod options to bash jhwilliams Programming 9 06-26-2007 12:13 PM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM


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