0

I have entered this shell script and its showing errors when compiling

echo Enter basic Salary
read bs
if [ $bs -lt 1500 ]
then
 hra= echo ´$bs \* 10 / 100´|bc
fi
gs= echo ´$bs + $hra´|bc
echo $gs

The errors are:

(standard_in) 1: illegal character: \302
(standard_in) 1: illegal character: \264
(standard_in) 1: illegal character: \302
(standard_in) 1: illegal character: \264
(standard_in) 1: illegal character: \302
(standard_in) 1: illegal character: \264
(standard_in) 1: illegal character: \302
(standard_in) 1: illegal character: \264
(standard_in) 2: syntax error
1
  • 1
    Nonfloating arithmetic is best done this way: hra=$((bs * 10 / 100)) (called Arithmetic Expansion). No need for an extra process. Commented Nov 28, 2013 at 12:22

2 Answers 2

1

One problem is (or, rather, 4 problems are) the use of ´ in place of ' or ".

There is another character in there also causing trouble, unless the acute accent is encoded in UTF-8 or UTF-16

Another problem is the use of spaces around assignments; these do not fly in the shell. You must not have spaces on either side of the assignment.

echo Enter basic Salary
read bs
if [ "$bs" -lt 1500 ]
then hra=$(echo "$bs * 10 / 100"|bc)
fi
gs=$(echo "$bs + $hra"|bc)
echo $gs

You don't really need the variable gs; you could write:

echo "$bs + $hra" | bc

Note that if bs is not less than 1500, you get a ill-defined value for hra (whatever happens to be left over, or blank if it is unset).

It looks like you have UTF-8 encoded data.

$ echo "´" | odx
0x0000: C2 B4 0A                                          ...
0x0003:
$ echo "´" | utf8-unicode
0xC2 0xB4 = U+00B4
0x0A = U+000A
$ bc | cat
ibase=16
obase=8
C2
302
B4
264
quit
$

U+00B4 is ACUTE ACCENT in Unicode.

Sign up to request clarification or add additional context in comments.

2 Comments

+1, and another problem is that variables must be double-quoted: "$bs", except in very few situations.
@JoSo: yes, see my update which I posted almost synchronously with your comment.
0

Too many Errors:

  1. As stated by Jonathan, is using ´ in place of `.
  2. Do not use space while assigning values to variables.
  3. Create the data before assigning it to a variable.

For e.g. hra=echo $bs \* 10 / 100|bc

Also, if the input exceeds 1500, then it will give out the error. So you need to do something with it.

For e.g. echo "Enter basic Salary" read bs if [ $bs -lt 1500 ] then hra=echo $bs \* 10 / 100|bc else hra=echo $bs \* 5 / 100|bc fi gs=echo $bs + $hra|bc echo $gs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.