LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-10-2007, 06:46 AM   #1
gubak
Member
 
Registered: Jul 2004
Posts: 332

Rep: Reputation: 30
Two questions about scripts


Hi!
I've created a script (it doesn't matter what it do). I want to run that script from everywhere (from /home directory from /etc etc.)with a single command. Is it possible? How?
Is it possible to give parameter for script?

Thanks
 
Old 05-10-2007, 06:56 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

If the script itself is placed in a directory that is in the PATH environment, you can access it from every point. You could encounter permission problems if the dir your are running the script from does not allow you to read/write (that depends also on what the script does).

If the script itself is placed in a directory that is nor in the PATH environment you can run it by including the full path to that script: /path/to/script/scriptname. But this could be seen as not being a single command....

Hope this helps.
 
Old 05-10-2007, 07:00 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Scripts you write yourself are often saved in ~/bin/. Add '$HOME/bin' to your PATH variable in ~/.profile.
 
Old 05-10-2007, 07:25 AM   #4
gubak
Member
 
Registered: Jul 2004
Posts: 332

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by druuna
Hi,

If the script itself is placed in a directory that is in the PATH environment, you can access it from every point. ...
What means PATH environment?
Do you know maybe how to add parameters to script? For example my script name is "premission". If I want it to run I type
Quote:
./premission
I want to give the parameter "62.5.3.15" (an IP of a machine)to the script. How can I do this?

Last edited by gubak; 05-10-2007 at 07:30 AM.
 
Old 05-10-2007, 09:06 AM   #5
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
is the parameter variable? you could use $1 as the variable in your script (whatever it is doing) and it will take it as a parameter so you'd type
Code:
permission <IP>
and it would use the IP in the script.
 
Old 05-10-2007, 10:03 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Quote:
Originally Posted by gubak
What means PATH environment?(an IP of a machine)to the script.
The PATH variable holds all directories that are searched when you call a program (or script).

Try echo $PATH from within a terminal and you'll see a lot of directories separated by a :. This makes it possible to run a program/script from any location, without having to remember and add the full path to that program/script. It's a lot easier to run ls instead of /bin/ls.

You can manipulate this (as jschiwal already wrote) and add your own directory (~/bin is often used to place home-made scripts). The standard PATH is set in /etc/profile, personal additions can be added in ~/.profile.

To add a directory to the PATH variable you something like this: export PATH=$PATH:/your/new/dir

Hope this clears things up a bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
3 Questions: X.org confs, GDM issues, and USB hotplug scripts KyPeN Linux - General 0 02-05-2007 02:23 PM
New install, questions on xorg and shutdown scripts Randux Arch 0 03-01-2006 08:28 AM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 01:10 PM
dyndns, scripts, various thoughts & questions Camino Linux - Newbie 2 10-23-2005 06:44 AM
Need help running scripts from scripts sdouble Linux - Newbie 3 05-31-2004 01:56 PM


All times are GMT -5. The time now is 04:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration