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 |
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. |
Scripts you write yourself are often saved in ~/bin/. Add '$HOME/bin' to your PATH variable in ~/.profile.
|
Quote:
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:
|
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> |
Hi,
Quote:
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. |
All times are GMT -5. The time now is 02:42 PM. |