ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
and then copied it to my bin directory in my home directory. but when i execute it outsite the bin directory it says command not found. i wrote some small scripts, i used the some process all works excepts for the one i stated above. what could be wrong?
Is your bin directory in your path (type echo $PATH)? Is the file executable (type ls -l /home/yourusername/bin/scriptname)? Do you have something like #!/bin/sh as the first line of the script? What do you get when you type ls -l /usr/local/squid/sbin/squid? Does your user account have permissions to the /usr/local/squid/sbin directory?
cd your-bin-directory-in-your-home-directory
chmod a+x your-script-name # permit ALL users to execute this file, see man chmod
PATH=$PATH:your-bin-directory-in-your-home-directory # include your directory in the PATH environment variable. Bash is searching for executables in all PATH dirs every time you type your command or run a script.
that should work. In fact you don't need to put the interpreter's path into your script, but it's worth to do for consistensy.
The above sequence will only change PATH in your current bash session, e.g. if you run other instance of bash you will need to set it again. To place your directory in PATH in all new bash sessions for all users, enlist it in the /etc/profile file in the export command. Or you can simply add this code to your ~/.bash_profile, which runs only for you.
- i tried putting my bin directory into the PATH using
Quote:
export PATH=$PATH:~/bin
and
Quote:
PATH=$PATH:~/bin
only both works i can now execute the command my theres a new problem the PATH that i specify is not being saved. whenever i exit the terminal open it again and excute the the script the command not found shows up again and when i check the echo $PATH my bin directory is not there. so i have to set it again. is there i can do whith this?
-i think i will try manually editing my .bash_profile
this is its content:
Quote:
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/login.defs
#umask 022
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
-i will try adding this:
Quote:
PATH=$PATH:/home/administrator/bin
-so my bash_profile will now be like this:
Quote:
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/login.defs
#umask 022
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.