LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Executing scripts (http://www.linuxquestions.org/questions/linux-general-1/executing-scripts-591052/)

jonette20 10-11-2007 08:28 AM

Executing scripts
 
Hi,

I am not a programmer.
I have never written a script. I know there are tutorials on the subject and I have one bookmarked.
My biggest question about scripts is where do you put them?
Sometimes the documentation on Linux might say, just run this perl script, or insert my script, how is this done?

Thanks in advance
jonette20

camorri 10-11-2007 08:46 AM

Quote:

My biggest question about scripts is where do you put them?
Generally you want to put scripts, in your PATH. To find out what your PATH is set to in linux, open a konsole, and run the command 'echo $PATH' with out the quotes. This is what my system looks like, just as an example.

Code:

echo $PATH
/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/games:/usr/java/jre1.6.0_01/bin:/usr/lib/qt3//bin:/home/cliff/bin:/usr/lib/qt3//bin

So If I created or copied a script I wanted to run, from the above a good place would be /usr/bin or /usr/local/bin.

The reason this will work, is because the PATH system variable is where the
system looks for executables, or commands when you type something in.

If you have a lot of your own scipts, I would suggest addign a directory, and then updating your PATH variable. In this way you keep scripts together
and separate from other binary files, just so you stay organized, and you,
the system admin knows where things are.

Quote:

Sometimes the documentation on Linux might say, just run this perl script, or insert my script, how is this done?
Perl scripts require Perl libs installed. Perl scripts are source, like commands that get fed through ( I think a perl interpreter ) and executed.

To run them, with the correct perl libs installed, just type the script name in a konsole. Of course the script permissions have to be set so your user, usually the owner, can execute them.

Hope this helps.

Bernard Swiss 10-11-2007 07:11 PM

Some distributions make advance allowance for a ~/bin directory.

For example, in Debian the ~/.bash_profile file may have some lines in it like this:
Code:

# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
    fi

This means all you need to do is make a "bin" directory in your home directory ( user@localhost:~ $ mkdir bin )

Then you can run any scripts that can run with just your permissions right from your home enviroment.

###################################
PS:

For this to work, you need to make sure that your xterm or xterminal-emulator (eg. gnome-terminal) is configured to act as a login shell -- otherwise the xterm won't read-in the .bash_profile.

Another option, is to justrun the script as
~/bin/your_script,
or from the home directory with
./bin/your_script,
or from wherever with
~/bin ./your_script.

In fact, ./your_script will work in whatever directory you have the script in
(eg ~/test_directory )

jonette20 10-15-2007 01:50 PM

Hi,

Thanks alot. Both of the answers were very informative and helpful.

jonette20


All times are GMT -5. The time now is 07:08 AM.