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?
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.
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.
精彩评论