detecting a file through bash or other means
Basically I am looking for this bash script functionality:
if [ -f /tmp/test ]; then echo "hi" fi via command line. It's usage is fairly specific so let me explain what I am doing. I need to use this command via ssh to determine remotely if a file exists. So I will do this: ssh machine_name some_command The trick is, I need the some_command to return true if the file exists or no-true if the file doesn't. SSH of course will then exit with the return code of some_command. The problem that I am running into is that the "echo hi" has it's own return code that is getting in the way. Any thoughts? |
"The trick is, I need the some_command to return true if the file exists or no-true if the file doesn't. SSH of course will then exit with the return code of some_command."
You can use the exit command to set the return code. I would use 0 for file exists and 1 for file does not exist. if [ -f /tmp/test ]; then echo "hi" exit 0 fi exit 1 --------------------------- Steve Stites |
Simply:
ssh machine_name '[ -f /tmp/test ]' Or did I understand something wrong? Yves. |
Note that -f is for testing that "it" exists AND is a regula file. For only testing existence, you have to use -e.
Yves. |
Quote:
|
All times are GMT -5. The time now is 08:54 AM. |