LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   where do i put my written scripts (https://www.linuxquestions.org/questions/linux-newbie-8/where-do-i-put-my-written-scripts-602830/)

mahmoud 11-27-2007 05:12 PM

where do i put my written scripts
 
hi
i have written a few scripts i want to be able to run them from any user and any directory
i have changed the permissions i just cant remember where to put the script so i can run it like any normal command for example
when you run
$ls
i want to run my script like that from anywhere

indienick 11-27-2007 05:33 PM

When you write your own scripts, you want to put them in a directory that's added to your $PATH environment variable. To see which directories are included in your $PATH, type
Code:

$ echo $PATH
at the CLI (Command Line Interface); the directories in the list are separated by colons ':'.

Note, to copy a script over to any of the directories listed in your $PATH, you more than likely need to be root;
Code:

$ su
Password: [type in your root password]
# cp -v myscript /copy/to/dir/

If you want to limit who can run the scripts to just you, create a directory in your home dir, and let's call it "bin":
Code:

$ mkdir ~/bin
Now, you have to add this directory to $PATH so that bash (assuming you're using bash) will know to look there:
Code:

$ echo "export PATH=$PATH:/home/user/bin" >> ~/.bashrc"
:)

PS. In case you're wondering, the '>>' means append whatever is on the left of it, to the file to the right of the sign.

Poetics 11-27-2007 05:42 PM

Most users have access to /usr/local/bin which exists for local binaries and related files -- I generally throw my systemwide scripts there.


All times are GMT -5. The time now is 01:54 AM.