John Smith
John Smith

Reputation: 719

Why is my shell script cutting off the first number in my output?

Here is my script:

mean1=$4.77953
echo "Mean: $mean1"

But instead of printing Mean: 4.77953 it prints Mean: .77953. What is causing this?

Upvotes: 1

Views: 212

Answers (3)

Reto Aebersold
Reto Aebersold

Reputation: 16624

Bash thinks $4 is a variable (the 4th argument passed to your script) in your mean1 declaration and this one is not set.

Upvotes: 2

Joao Morais
Joao Morais

Reputation: 1925

Bash is expanding $4 to the fourth argument of your script. You should single quote your string in order to avoid the expansion.

mean1='$4.77953'

Upvotes: 1

Federico Picci
Federico Picci

Reputation: 1113

You put $ by accident in front of 4

try

mean1=4.77953

Upvotes: 2

Related Questions