command line arguments problem.

Reply

Join Date: Feb 2006
Posts: 2
Reputation: Prestwick is an unknown quantity at this point 
Solved Threads: 0
Prestwick Prestwick is offline Offline
Newbie Poster

command line arguments problem.

 
0
  #1
Feb 9th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: command line arguments problem.

 
0
  #2
Feb 13th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2
Reputation: Prestwick is an unknown quantity at this point 
Solved Threads: 0
Prestwick Prestwick is offline Offline
Newbie Poster

Re: command line arguments problem.

 
0
  #3
Feb 13th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC