This is driving me nuts error on line 17


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting This is driving me nuts error on line 17
# 1  
Old 11-22-2014
This is driving me nuts error on line 17

There is an error in this script on line 17 bee at it for 12 hour trying to find the problem, just lost. please help a newbie.
Code:
line 17: [: expr: integer expression expected 1

Code:
 #!/bin/sh
  2 ## Name of the program is test_script_b.sh
  3 
  4 ##request information from the user
  5 echo enter 3 numbers
  6 read a b c
  7 
  8 ##check for proper range of numbers
  9 if [ $a -gt 10 -o $b -gt 10 -o $c -gt 5 ]; then
 10 echo "numbers out of range"
 11 exit 1
 12 fi
 13 
 14 ## process data
 15 x=($a + $b + $c)
 16 
 17 while [ $x -gt 0 ]
 18 do
 19         echo "(($x / 2 % 2))"
 20         x=(expr $x - 1)
 21 done
 22 
 23 ## end of program

~

Last edited by Scrutinizer; 11-22-2014 at 04:56 PM.. Reason: code tags
# 2  
Old 11-22-2014
Try:
Code:
14 ## process data
15 x=$((a + b + c))
16 
17 while [ $x -gt 0 ]
18 do
19   echo "$((x / 2 % 2))"
20   x=$(( x - 1))
21 done

# 3  
Old 11-22-2014
thank you very much that fixed it. but the question is way, i am just learning unix and the book i am using is not very good.Smilie
# 4  
Old 11-23-2014
Hi, your are welcome. A good thing to do is run your script with the -x option and use echo statements to debug. For example:
Code:
set -x
read a b c
x=($a + $b + $c)
echo "$x"
x=$((a + b + c))
echo "$x"

This will show something like:
Code:
+ read a b c
2 7 21
+ x=($a + $b + $c)
+ echo 2
2
+ x=30
+ echo 30
30

which allows you to see more of what is going on.

The other thing is get a good book. There are several threads on these forums about this topic.
# 5  
Old 11-23-2014
thank you for the help will look into a better book. Script writing has been my weak point, but in todays market it is needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Hardware

Name These Little Nuts for my Server Cabinet?

I bought a server cabinet recently and the person who sold it to me included some strange nuts. Can anyone tell me what they are called? I need to buy more. Below is the image of them. Thank you! http://s23.postimg.org/50fx2ge6j/image.jpg http://s23.postimg.org/o498isr0r/image.jpg ... (1 Reply)
Discussion started by: danijeljames
1 Replies

2. Homework & Coursework Questions

Abnormal producer consumer problem driving me nuts

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: normally, i hate asking someone to do my homework for me but am getting desperate right now. i have a project... (1 Reply)
Discussion started by: alexantosh
1 Replies

3. UNIX for Dummies Questions & Answers

Abnormal producer consumer problem driving me nuts

normally, i hate asking someone to do my homework for me but am getting desperate right now. i have a project about consumer producer problem. the deadline is tonight at 23:55. but i havent gotten it working yet. i just COULDNT get it to work right yet. the problem is as follows: the C - program... (0 Replies)
Discussion started by: alexantosh
0 Replies

4. Shell Programming and Scripting

Escape Characters are driving me crazy!

Hi everyone, Is there anywhere I can find a complete table of all characters that must be escaped by the various UNIX shells and scripting languages? It seems every command/shell/scripting language has different rules about what characters must be escaped. I do a lot of searching and... (3 Replies)
Discussion started by: troym72
3 Replies

5. Shell Programming and Scripting

Short code driving me nuts.

Hello guys I am trying to learn perl and have a simple calculator I am trying to run but I get error runaway multi-line. Can someone point this rookie in the right direction. ### print 'Welcome to the Calculator'; print 'Would you like to enter the calculator? Please Type y or n'; $run =... (9 Replies)
Discussion started by: daddygrant
9 Replies

6. Shell Programming and Scripting

Pleas help..this is driving me crazy

Hi, I've created a script in csh that takes a file and checks it for mispelled words. Im almost done but I need to do two more things but I need help. First, when displaying an incorrect word to the user, I need to show the line of the input file that contains the word. Second,if the user... (0 Replies)
Discussion started by: hckygoli31
0 Replies

7. UNIX for Dummies Questions & Answers

Dumb question but its driving me nuts

I use a tcsh and I need to monitor a file that its constantly updating. In the past I remember using less -(an option) fileName. This option told less to keep listening to this file and output the any changes. What is this option??? I think I read the man page for less like 5 times and I... (3 Replies)
Discussion started by: jepombar
3 Replies

8. Shell Programming and Scripting

Simple test driving me mad!

Hi all, I have been writing a script to automate some work for myself and have come accross a problem. I cannot understand why it doesn't work, but then I am new to both Unix and Korn shell hacking! Here is the problem: I want to interogate a file for a number and store that number in... (6 Replies)
Discussion started by: alarmcall
6 Replies

9. UNIX for Dummies Questions & Answers

unix driving me crazy

:( :confused: what is performed by the following unix command: grep -v Jane project1.txt and grep ' 5\..' janet.txt (1 Reply)
Discussion started by: Tendernisin
1 Replies
Login or Register to Ask a Question