LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (http://www.linuxquestions.org/questions/red-hat-31/)
-   -   Shell won't execute commands.... (http://www.linuxquestions.org/questions/red-hat-31/shell-wont-execute-commands-423597/)

frank320 03-10-2006 03:20 PM

Shell won't execute commands....
 
Could anyone explain the below....

The command "kmtest" is defined as:

Quote:

[root@localhost kurt]# cat kmtest
#!/bin/sh
ls
# EOF

It has permissions as follows:

Quote:

[root@localhost kurt]# ls -lc kmtest
-rwxrwxr-- 1 kurt kurt 19 Mar 10 14:54 kmtest
Yet, when I try to execute it, the result is "command not found"...

Quote:

[root@localhost kurt]# kmtest
bash: kmtest: command not found
[root@localhost kurt]#
Help would be appreciated....

nadroj 03-10-2006 03:22 PM

try /.kmtest

benjithegreat98 03-10-2006 05:19 PM

I think nadroj was trying to say
Code:

./kmtest
Must've been reading too much slashdot lately, eh? :)

Robhogg 03-10-2006 06:14 PM

A little explanation:

When you type a command at the prompt, by default Linux will search in the directories contained in the PATH environment variable. You can see the contents of this variable with:
Code:

echo $PATH
Using ./ before the command forces linux to run it from the current directory (referenced by the first dot). You could also run it by specifying the full path.

To be able to run a command from anywhere in the system, therefore, you can place it in one of the directories identified in PATH. You will probably find that you have a bin sub-directory in your home folder, and that this is already in PATH. If you do not have such a directory, you can create it, and then add the following lines to your shell's config file (if you're using bash, this is .bashrc which will be in your home folder):
Code:

PATH=${PATH}:/home/<username>/bin
export $PATH

This will be added next time a shell is opened. After adding a new script / command to your bin directory, you may then find you have to run hash -r to renew the shell's list of command locations.

Rob

nadroj 03-10-2006 09:37 PM

:p yes benji.. thanks

frank320 03-11-2006 04:57 AM

Many thanks for your help... I'll have to pay attention to PATH...

peterdavid 03-17-2006 12:12 PM

questions like this should be in newbie section

just saying is all


All times are GMT -5. The time now is 06:37 PM.