Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

bash - Variable variable assignment error -"command not found"

When I run the script I get the following errors. What am I doing wrong here please? Any help appreciated- Bash Newbie

Error:

line 12: 0=1: command not found
line 13: 0=1: command not found

My Script:

count_raw=0
avg_raw=0

$count_raw=1
$avg_raw=1

echo "count_raw=$count_raw"
echo "avg_raw=$avg_raw"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

= is an assignment operator when found free and $ holds value (not only in USA but in bash too) of a variable.

So when you say: $var=1, you're essentially trying to type a random string (0=1 in your case) in bash and bash doesn't like that. Look at the one-liner below that shows one example where you'd type in $var=1 and bash would be able to process it:

var=1; if [[ $var=1 ]]; then printf "Congrats! You have learned the difference between variable assignment and variable comparison in the ${var}st attempt.
"; fi;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...