imaginecode
imaginecode

Reputation: 5

Error when I try to make a shell script executable

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"

Upvotes: 0

Views: 98

Answers (1)

bryn
bryn

Reputation: 3325

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"

Upvotes: 2

Related Questions