LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-11-2011, 04:29 AM   #1
porkcharsui
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 0
Help, my script won't exit.


Hi all,

When I run my script(attachment) and I use an option(-l -u -r) that requires an argument, it should exit if the argument isn't supplied, but it doesn't. How do I arrange this? Can anyone help me?

Thanks for any help in advance.
Attached Files
File Type: txt syncit.txt (5.4 KB, 8 views)

Last edited by porkcharsui; 02-11-2011 at 04:30 AM.
 
Old 02-11-2011, 05:44 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,655

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
Firstly:
Code:
while (( "$#" > "0" ))
This a numeric comparison and not a string one so none of the quotes are required.
Secondly, when you have no arguments the loop will enter once for the '--' argument and perform the shift. This then sets $# = 0 so the loop exits.
Remember your loop only caters for incorrect entries to exit and not for none.

I think you need to test for number options passed in prior to the getopts loops.

Hope that helps.
 
  


Reply

Tags
bash, getopt, shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] exit in script files cause konsole terminal itself to exit Star_Gazer Programming 11 04-12-2010 09:32 AM
A script called by another script would always give exit status other than Zero(0) vandana Linux - General 2 03-22-2010 05:26 AM
regarding exit bash script m4manoze Linux - Newbie 6 03-08-2010 06:19 AM
call another script and have the inital script exit mjtice Programming 1 09-11-2005 12:54 PM
script 'exit' command kilobravo Linux - General 8 01-16-2003 04:24 PM


All times are GMT -5. The time now is 06:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration