Hello all,

Essentially a newbie to shell scripting (and Unix/Linux as a whole!) Essentially doing this project for my year in work placement. Essentially it is a script which searches for specific files and backs them up to tape. However I need to modify said script so it can verify that it has all the files that it needs before writing to tape.

However before I can do that I need to go and write an if loop that includes a command line argument so I can run the script in test mode and prevent it to write to tape so I can test the file checking feature.

Now I'm in sixes and sevens in trying to work out how to get this loop to work. I'll post the actual loop in code at first but if you need the entire code I'll have to do some er *alterations* (hush hush you see):

if [ $# -test 0 ]; then
echo @skipping tape dump - diagnostic test mode@
else
tar tf $tapedevice
fi

Now whenever I save that and try and excecute it, it comes up with...

./test5.sh: line 27 [: -test: binary operator expected

It then goes straight to trying to back up to tape. On this machine however there is no tape drive so it can't find it so it collapses xD

Can anyone help me?

Recommended Answers

All 2 Replies

#!/bin/ksh
if [ $# -eq 0 ]; then
        echo  "$# is zero "
else
        echo "$# is greater than zero"
fi

Thanks for the hint! :)

Sorry I should have worded my original post differently after I saw the guidelines for posting. I don't really want the answer just hints and tips for a budding beginner :)

Thanks again. If I succeed or fail I'll let you chaps know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.