Use of ./ in executing a script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of ./ in executing a script.
# 1  
Old 05-26-2010
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 ./myscript?

I would also like to know the difference in running a script as ./myscript and . /myscript(with white space).

Any help from you in understanding this would be highly appereciated.

Thanks,
Chandan
# 2  
Old 05-26-2010
./ means you are specifying the path (location) of script.

it means the shell will execute the script from the current pwd.

Its same if you give complete path like /home/amit/myscript.sh
else if you are in the /home/amit/ -- then ./myscript.sh

Last edited by amitranjansahu; 05-26-2010 at 03:08 AM.. Reason: typo
This User Gave Thanks to amitranjansahu For This Post:
# 3  
Old 05-26-2010
Quote:
Originally Posted by singh.chandan18
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?

It executes a script that is in the current directory instead of where it belongs, which is in a directory in your $PATH.
Quote:
What if I have already defined a bang in the script say #!/bin/ksh and then running the script as ./myscript?

The shebang tells the OS (or your shell) what interpreter to use to run the script.
Quote:
I would also like to know the difference in running a script as ./myscript and . /myscript(with white space).

./myscript is described above.

. /myscript will attempt to source (not execute) a script located in /, the root directory, where it should never be.
This User Gave Thanks to cfajohnson For This Post:
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. 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

3. UNIX for Dummies Questions & Answers

Script not executing

Hello, I wasn't sure where to post this so I posted it here. I've used UNIX quite a bit, LINUX not so much. For some reason, my LINUX script will not execute if I type in the script name and press enter. I'm in the directory where the script is. test.sh However, when I use ". ./" it... (5 Replies)
Discussion started by: jsanders
5 Replies

4. Shell Programming and Scripting

executing one script from other

Script test #! /bin/csh -f echo checking the sset command if( -e /home/user/project/runtest/testdir/ts ) then echo ts script present set cmd = "/home/user/project/runtest/testdir/ts a 1 b 2 c 3" else echo script not present endif echo $cmd echo done script ts #!/bin/csh -f set... (1 Reply)
Discussion started by: animesharma
1 Replies

5. UNIX for Dummies Questions & Answers

Help with executing script

Dear All, I have a script on my USB and I want to execute it on set of files when I connect via ssh on the server ... I'm not able to define the path of the script located in the USB ... how can I use this script without copying/moving it into the directory I'm working on in the ssh mode ....... (6 Replies)
Discussion started by: pawannoel
6 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. 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

8. 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

9. Shell Programming and Scripting

executing script

Hello ; I have a script myscript.sh. If I type at prompt myscript.sh I will receive ksh: myscript.sh: not found but if I type ./myscript.sh it works . What should I do to be able to run myscript just typing myscript.sh Many thanks before. (1 Reply)
Discussion started by: big123456
1 Replies

10. Shell Programming and Scripting

script not executing

test:/oracle/home $ ex_im1.sh ksh: exp_imp1.sh: not found $echo $SHELL /bin/ksh ex_im1.sh has rwxr--r-- permissions thanks (3 Replies)
Discussion started by: dreams5617
3 Replies
Login or Register to Ask a Question