1

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

Just as you said, it doesn't has exe permission and need add ./

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.