Difference between ./ & . ./ ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difference between ./ & . ./ ???
# 1  
Old 03-04-2005
Question Difference between ./ & . ./ ???

For executing a shell script, i know 2 ways:
1) using sh command
2) making the script file executable & then use ./

But i can across another way for executing the scripts... using ". ./"
I tried this way.. but i was able to understand the difference between "./" and ". ./"

I would be very grateful if any1 can help me????? Smilie

Thanx in advance
# 2  
Old 03-04-2005
When you make a script executable and invoke with ./myscript, you are specifying the path to the script (i.e. "." - the current directory). The script will then be interpreted by whatever interpreter you've sepcified in your shebang line (#!/bin/sh, for example) at the top of the script. This script will be executed in a child shell, and any variables set in the parent shell that aren't exported will not be available to the child. Also; even if you export variables in your script, they still won't exported "up" to the parent.

If you had the current directory (".") at the end of your PATH, i.e. PATH=$PATH:. you could then omit the ./ part. This is particularly bad form, and is a security risk, so I would err against this under all circumstances! It's far safer to explicity say you want to execute a script in the current directory by specifying the path (./).

When you type . ./ you are executing the commands contained within the script in the current environment, so that, for example, any variables set in the current environment that aren't exported become available to your script, and any variables set in your script become available in the current environment... observe...

Code:
$ a=1
$ cat > my_script
echo a is $a
b=2
$ . ./my_script
a is 1
$ echo $b
2

Cheers
ZB
# 3  
Old 03-04-2005
Thanx zazzybob.. for your reply..
I am very thankful for your explanation....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

2. Shell Programming and Scripting

About date & time difference

Hello All, I was having a look on threads on the Forum about time calculation but didn't find exactly this issue. For instance, if we have these 2 dates, begin & end : 20100430235830 20100501000200 Is there anyway, awk, ksh, perl to calculate the difference in sec and get for... (6 Replies)
Discussion started by: rany1
6 Replies

3. Linux

What is the difference between flavour & distribution.

Hi All, Can anyone tell me the difference between flavour & distribution? As we say that - AIX, Linux, Solaris etc are the flavours of Unix & fedora, ubuntu, suse etc are the distributions of linux. Can anyone explain me, why it is called so. Thanks in advance. Amol (6 Replies)
Discussion started by: Amol21
6 Replies

4. Solaris

difference b/w sol9 & sol10

what is the difference b/w sol9 and sol10 booting procedure?? Recently faced this question with HP... Thiru (2 Replies)
Discussion started by: tirupathiraju_t
2 Replies

5. Solaris

Difference between sudo & RBAC

Hello Everybody I would like to know any major difference between sudo & RBAC as I am bit familiar with RBAC but not with sudo (2 Replies)
Discussion started by: girish.batra
2 Replies

6. UNIX for Advanced & Expert Users

Difference between s & S in setuid in UNIX

Hi, what is the difference btwn s and S in setuid , access permissions. I have to make to change the access permissions of a file to rwsr_xr_r but if i type in 4655 it changes the file to rwSr_xr_r . How can I make this change ? Please suggest. (2 Replies)
Discussion started by: astha rais
2 Replies

7. UNIX for Advanced & Expert Users

Difference between <stdin> & terminal

Hi, What's the difference in taking inputs from <stdin> and terminal. When by default <stdin> points to terminal itself. Thanks (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

8. UNIX for Dummies Questions & Answers

Difference between && and -a

I've come stuck when I was making sure the hour of the day was not been two times so that the rest of the script could not be executed. Seems simple enough. I used the -a to join the two conditions together and it would run if the conditions was t/f ( it is only supposed to run if was t/t).... (3 Replies)
Discussion started by: spookyrtd99
3 Replies

9. UNIX for Advanced & Expert Users

What is the difference between Unix & linux

:confused: Hi All Can anyone help me in finding the answer of the question mentioned below. What is the difference between Unix & linux ? Thanks in Advance to all CSaha (1 Reply)
Discussion started by: csaha
1 Replies

10. UNIX Desktop Questions & Answers

what is the difference between Unix & linux, what are the advantages & disadvantages

ehe may i know what are the difference between Unix & Linux, and what are the advantages of having Unix as well as disadvantages of having Unix or if u dun mind i am dumb do pls tell me what are the advantages as well as the disadvantages of having linux as well. thanks (1 Reply)
Discussion started by: cybertechmkteo
1 Replies
Login or Register to Ask a Question