Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-08-2012, 06:10 PM   #1
Registered: Apr 2012
Posts: 100

Rep: Reputation: Disabled
condition to exit


i want that the program will exit if the file does not consist @

i wrote this code however it does not run :

i will be happy for explanation why the script does not run and hoe to solve it

thanks in advance

fail=`echo $line | grep @`

if (( $?-eq 1)); then

exit 1

Old 04-08-2012, 06:34 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
I am assuming you are using bash as your shell.

You have two separate problems.

1. The (( )) construct is to perform arithmetic. To perform tests on values, you use the [[ ]] construct

2. You must be mindful of spaces inside your condition. There must be a space between $? and your operator (-eq). There must also be a space between your last operand (1) and the end of the test condition (]])


fail=`echo $line | grep @`
if [[ $? -eq 1 ]]; then
  exit 1


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
while () not exiting even when exit condition is met aatwell Programming 28 09-15-2008 08:49 PM
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 05:02 PM
Warning: at kernel/exit.c:814 do exit() (Tainted: P ) <- nVidia video problem? Hitboxx Fedora 2 10-06-2007 10:47 PM
difference between exit 1 and exit kushalkoolwal Programming 6 10-20-2005 04:56 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:58 AM.

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