Spark
Spark

Reputation: 672

Cannot execute bash script in redhat linux

I write a simple shell script to clean log files in redhat:

Filename: clean.sh

#!/bin/bash
rm -f *.log core.*

But when I typed clean or clean.sh, it always prompt

-bash: clean: command not found
-bash: clean.sh: command not found

What's the problem?

Upvotes: 1

Views: 6690

Answers (2)

yati sagade
yati sagade

Reputation: 1375

problem 1: maybe the execute permission on clean.sh is not set. Do this:

chmod +x ./clean.sh

problem 2: RH Linux does not include CWD on the path by default. So, when you are in the same directory as clean.sh, type:

./clean.sh

That should execute it.

Upvotes: 2

Keith Thompson
Keith Thompson

Reputation: 263237

You probably don't have . (the current directory) in your $PATH (and that's a good thing; having . in your $PATH can be dangerous.)

Try this:

./clean.sh

And if the script file's name is clean.sh you can't run it as just clean, with or without a directory. The file name is clean.sh, and that's how you need to execute it.

Or you can change the name from clean.sh to just clean. Unix-like systems (that includes Linux) don't depend on file extensions the way Windows does.

Upvotes: 3

Related Questions