944,067 Members | Top Members by Rank

Ad:
Feb 9th, 2006
0

command line arguments problem.

Expand Post »
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):

Quote ...
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...

Quote ...
./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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Prestwick is offline Offline
2 posts
since Feb 2006
Feb 13th, 2006
0

Re: command line arguments problem.

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh
  2. if [ $# -eq 0 ]; then
  3. echo "$# is zero "
  4. else
  5. echo "$# is greater than zero"
  6. fi
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
Feb 13th, 2006
0

Re: command line arguments problem.

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Prestwick is offline Offline
2 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: shell script for number sequence--- anybody help me?
Next Thread in Shell Scripting Forum Timeline: A wierd problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC