LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   script wont work? (https://www.linuxquestions.org/questions/programming-9/script-wont-work-503158/)

SBN 11-19-2006 11:39 PM

script wont work?
 
-hello guys i wrote a script containing this line

Quote:

/usr/local/squid/sbin/squid -k shutdown
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?

gilead 11-20-2006 12:52 AM

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?

Sorry it's just a lot of questions... :)

GNUlancer 11-20-2006 05:34 AM

Code:

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.

GNUlancer 11-20-2006 05:37 AM

To find out, how bash works, try man bash
Use '/' for searching, 'n' to go to the next result, and 'h' for help on other browsing functions.
Have fun

SBN 11-21-2006 01:02 AM

- 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?

gilead 11-21-2006 05:09 AM

If you're using bash as your shell, you should be able to put the following in ~/.bash_profile:
Code:

export PATH=$PATH:~/bin
You might have to expand the '~'...

GNUlancer 11-21-2006 07:41 AM

See my post ^^

you should put it in the /etc/profile for all users (it executes first) OR in ~/.bash_profile only for you

SBN 11-21-2006 08:35 PM

-this is my echo $PATH

Quote:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
-i added my bin directory using these commands

Quote:

export PATH=$PATH:/home/administrator/bin or
export PATH=$PATH:~/bin or
PATH=$PATH:/home/administrator/bin or
PATH=$PATH:~/bin
all have the same output when i check my PATH
Quote:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/home/administrator/bin
-this works actually but when i close the terminal and check my PATH again it return to this

Quote:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
-its not saving, why is that?

-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

PATH=$PATH:/home/administrator/bin

-is it correct?

gilead 11-21-2006 08:54 PM

I'd use:
Code:

export PATH=$PATH:/home/administrator/bin


All times are GMT -5. The time now is 11:54 PM.