LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command not found (https://www.linuxquestions.org/questions/linux-general-1/command-not-found-749888/)

neda.hd 08-24-2009 10:22 AM

Command not found
 
Hello,

I am trying to run a shell script. The script is made executeable using both following commands;

chmod +x sub.sh
chmod u+x sub.sh

However, when running sub.sh I receive the following;

sub.sh: Command not found

Would some one please help me find out what causes this? I appreciate your help.

Many thanks,

Neda.

repo 08-24-2009 10:24 AM

Welcome to LQ

If you are in the directory, where the file is, you need to use
Code:

./sub.sh
since it is not in your path
or use the whole path to the file
Code:

/home/user/whateverdirectory/sub.sh

colucix 08-24-2009 10:26 AM

If the script sub.sh is not in a directory included in the PATH environment variable, you have to specify the absolute or relative path on the command line. If you want to launch an executable placed in the current working directory you can simply do
Code:

./sub.sh

neda.hd 08-24-2009 12:40 PM

Re: Command not found
 
Hi,

Thanks for the welecome message and your response.

I am in the directory where the file is. However, even "./sub.sh" is generating the same : Command not found message.

I have two similar packages that use same codes and scripts, with some deferences in input and output files and calculations. Script in one package is running perfectly but script in this second package is creating Command not found. Both scripts from both packages are the same and are using the same environment.

Would you please advice?

Thanks very much,

Neda.

Disillusionist 08-24-2009 01:00 PM

Please show the output from:
Code:

ls -l sub.sh

druuna 08-24-2009 01:03 PM

Also post this please: file sub.sh

I suspect that the sub.sh might be seen as a dos/windows file.

neda.hd 08-24-2009 01:36 PM

Command not found
 
The output from:
Code:

ls -l sub.sh
is;

Code:

-rwxr-xr-x  1 nnhh    office    1837 Aug 24 12:12 sub.sh
The other script that runs perfectly though creates the following output from the same command;

Code:

-rwxr--r--  1 nnhh    office    1201 Aug 24 10:21 sub.sh
Thanks very much for your help,

Neda.

repo 08-24-2009 01:37 PM

Or you can post the contents of the script

neda.hd 08-24-2009 02:04 PM

Command not found
 
Here is the script;

#!/bin/sh

. $HOME/.profile

FEDS=/directory
FEDSBIN=/directory/bin
CRON_DIR=$HOME/cronDir
. $CRON_DIR/scrubReport/MBS_ScrubReport/env.sh
export HOME FEDS FEDSBIN LD_LIBRARY_PATH

STARTAPP_DIR=/home/directory/bin export STRATAPP_DIR
OUT_DIR=home/scrubReport/output
LOG_DIR=home/scrubReport/logs

#---Running subMain.cpp through scrub.sh and redirecting the output----

/bin/rm $OUT_DIR/errors_mbs.csv
/bin/rm $LOG_DIR/logs_mbs.csv


${STARTAPP_DIR}/startApp -c 1 -m 4048 -w 5 -z 600 -i "server5" -s "cd cronDir/scrubReport/MBS_ScrubReport; scrub.sh">/home/scrubReport/logs/logs_mbs.csv 2>/home/scrubReport/output/errors_mbs.csv


Thanks a lot,

Neda.

Disillusionist 08-24-2009 02:11 PM

Hard to tell without [ CODE ] tags around the code.

There appears to be a typo: export STRATAPP_DIR and that should be on a new line, but that shouldn't cause the issue that you are reporting.

What did you get from:
Code:

file sub.sh
Also what do you get from:
Code:

ls -lb sub.sh

neda.hd 08-24-2009 03:03 PM

Thanks.

from:
Code:

file sub.sh
I get the following:
sub.sh: executable shell script

and from:
Code:

ls -lb sub.sh
I get the following;
-rwxr--r-- 1 nnhh office 1825 Aug 24 16:00 sub.sh*

Thanks,

Neda.

Disillusionist 08-24-2009 03:43 PM

Aha, that explains a few things.

It looks like you have a non-printing character in the file name.

You need to rename the file:

Code:

mv sub.sh* sub.sh

neda.hd 08-24-2009 04:35 PM

Command not found
 
No renamed the file. This didn't work either. Thanks.

Any other ideas???

Thanks,

Neda.

repo 08-24-2009 08:18 PM

Can you run it as root?
try
Code:

chmod 755 sub.sh

neda.hd 08-25-2009 07:53 AM

Hello,

Thanks for all your helps.

Running as a root did not help either.

What else could be wrong?

Thanks,

Neda.


All times are GMT -5. The time now is 10:39 PM.