0

I made a script called addition and tried to run it with the sh command in bash. It would produce the error when I try to run it. But it works fine when use chmod +x filename

5e: 5: 5e: let: not found
5e: 6: 5e: let: not found
5e: 7: 5e: let: not found
a + b = 

Here is the script itself

let a=$1
let b=$2
let sum=a+b
echo "a + b = $sum"
1
  • Is your $SHELL set to /bin/bash? Commented Sep 23, 2014 at 23:31

1 Answer 1

2

The script has no header, so when you execute it your current shell (bash) runs it. When you do 'sh addition' you are running it through 'sh' (which could be dash). Your code is bash, so you must run it with bash rather than sh. You should put this in the top of your script and run it by executing it (after chmod +x):

#!/bin/bash

Your script would then look like:

#!/bin/bash
let a=$1
let b=$2
let sum=a+b
echo "a + b = $sum"
Sign up to request clarification or add additional context in comments.

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.