Difference in Executing a Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difference in Executing a Script
# 8  
Old 07-26-2006
Shivdatta,

Not to confuse the issue... But this is my understanding.
Quote:
1) . ./filename

2) ./filename
1) The dot with a space tells the shell to source the file. The dot slash tells the shell the file is in the current directory.
Example. You have two script files. One called "run" the other called funct.

Your funct file would look something like this.
Code:
lsd ()
{ ls -al $1}

Your run file would look something like this.
Code:
#! /bin/ksh
. /path-to-file/funct
programming stuff
lsd some-file

When you execute run it will source the fuctions into the current shell. Then you simply call the function from within your script. This is most useful for common functions used in many scripts. You need only type the functions in once when creating the funct file. Then you source in the functions in any other script you need them in. This can also be used from the command line to source functions into your current shell. You can then use these fuctions as if they were commands.

2) Simply tells the shell to execute the file in the current directory. Mostly used when the directory your in is not in your PATH, or there are mutiple prgrams with the same name (Bad Idea) and you want to run the instance in the current directory.

Hope this helps.
# 9  
Old 07-26-2006
1)./ means you have file in your current directory and from where you want to use.

2).<space>filename means you want to run the file in the current shell.The . command executes a script without using a subshell.it also doesn't require the script to have executable permission.

the use of this is to keep some function in file and run that file as
. filename then u can use those functions in a command line directly as you use commands.

one more use is to modify .profile file and you want to reflect changes without rebooting run the command
.<space> .profile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Oracle script from UNIX Script

Hi, I am new to UNIX and want to execute oracle script from unix script. I have written below script but i am getting below error. #!/bin/bash file="/home/usr/control/control_file1" while read line do #$line=@$line #echo $line sqlplus tiger/scott@DB @$line exit #echo "$line" done... (3 Replies)
Discussion started by: vipin kumar rai
3 Replies

2. Shell Programming and Scripting

Difference in executing the script

Hi Team, a silly question. Let's say i have a script called xyz.ksh what is the difference in executing the script as follows? ./xyz.ksh ksh xyz.ksh Thanks (2 Replies)
Discussion started by: kmanivan82
2 Replies

3. UNIX for Dummies Questions & Answers

Script dosent exits after executing the script

Hi i wrote a script which dosent exists after executing any help #!/bin/bash netstat -ptlen | grep 10000 if ; then echo "Hive Thrift server is running" exit 0 else echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com `nohup hive... (7 Replies)
Discussion started by: vikatakavi
7 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

Use of ./ in executing a script.

Hi Guys, Hope you are doing well out there. Can you please let me know why do we use "./" to run a shell script? Is it to run the script in the current shell or something else? What if I have already defined a bang in the script say #!/bin/ksh and then running the script as... (2 Replies)
Discussion started by: singh.chandan18
2 Replies

6. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

7. Shell Programming and Scripting

What is the difference executing a script with . in the front versus not putting a "."

Hi All, I know this has been discussed a lot but still I need some more answers. I am running this is ksh on AIX 5.3 I believe putting a "." in front of the script will start a new shell, is that correct?? I have a script which override some PATH variables and it does not do that... (3 Replies)
Discussion started by: Hangman2
3 Replies

8. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies

9. Shell Programming and Scripting

script not executing

Hi , Kindly advice whats wrong with this script. It is not executing. ...# #!/bin/ksh find. -name "b.log" if ; then echo "1" fi ...# Thanks (5 Replies)
Discussion started by: himvat
5 Replies

10. UNIX for Dummies Questions & Answers

Difference between executing a shell using sh and .

Is there any difference in executing the shell using sh and . and ./. I had a shell script and i observed that anyone is ale to execute the script eith sh even without having the execute permission.how is so? (2 Replies)
Discussion started by: soumyo_das
2 Replies
Login or Register to Ask a Question