Results 1 to 10 of 14
hello there
If have come across three ways of executing a script
Code:
bash script
. script
./script
So what is the difference in the above 3 methods
Also if ...
- 07-07-2009 #1
different ways of executing a script
hello there
If have come across three ways of executing a script
So what is the difference in the above 3 methodsCode:bash script . script ./script
Also if you know some other method of executing script please add in.Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 07-07-2009 #2
"bash script" is an instruction to run bash, passing the script to bash as an argument. Any bash script can be run like this.
The second method is called "sourcing" the script and is used to incorporate one script within another. The script is run as if it was part of the script that sourced it.
Neither of these methods requires the script to be executable. The third method, which is the commonest way of running a script from the command line, does require the script to be executable (i.e. the execute bit must be set) and to start with the line. This "hash-bang" line tells Linux that bash is the program which must be used to read and execute the script. The initial dot and slash in the command simply means "you will find the script I mean in this directory".Code:#! /bin/bash
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 07-08-2009 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
Okay, what do I have to do to run a script without putting the ./ in front of it?
I was trying to use a program that uses spidermonkey and everything is dependent upon just typing "js" at a command prompt. I have to type: ./js on my Debian box.
What gives?
Or is it assumed that if the author states: type "js" at the command prompt... that what is really meant is to type in "./js".
Can you explain - please?
- 07-08-2009 #4
that means that it assumes that it is on your path
most applications will get installed to /usr/bin or /usr/local/bin which will be on the path of the user, so when you type that command, the shell looks for the application in the directories on your path, and then executes that
- 07-08-2009 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
So if I have an application installed in /usr/src/js/src and the command from there is ./js can I make a link (ln) in the /usr/local/bin to that command and it will work?
Thank you for your reply.
- 07-08-2009 #6
Yes, as long as /usr/local/bin is in your path. You can check you path by doing a:
This will output a list of different paths seperated by the : symbolCode:echo $PATH
Linux User #453176
- 07-08-2009 #7Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
That did it! Thank you.
Today is a good day. I've learned something new and it's only 8:04am.
Thank you again.
- 07-08-2009 #8
There's another possibility for this kind of thing which doesn't require you to mess around with system directories. If you create a bin subdirectory in your home directory and put scripts in there, they will execute as simple commands because ~/bin is on your command path in most distros.
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 07-08-2009 #9
~/bin is not there in the path by default , it is only /bin
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 07-09-2009 #10


Reply With Quote
