0

So I'm pretty new to bash scripting but so far tldp.org has been a good friend. Anyways I've confused myself and swearing to much so looking for help in clarification: I declare a variable like such
MAXseeds=-1; sumS=0 I do a bunch of things in my script and get a new value for sumS which is an integer value. I would then like to compare MAXseeds and sumS if sumS is larger make MAXseeds equal to sumS. I do this by:

  echo $MAXseeds      
  echo $sumS    
  if [ $MAXseeds -lt $sumS ];
  then 
     MAXseeds = $sumS
     best_file=$COUNT
  fi 
  echo $MAXseeds

This from what I can tell should work however the terminal output I get when running over this section of script is

  -1
  492
  lookup.sh: line 34: MAXseeds: command not found
  -1

Basically I am wondering what I am doing wrong here? why does it respond with command not found? Any explanation to why this is incorrect would be greatly appreciated.

1
  • 1
    Don't destroy the question by removing the flaw. Give the guy who answered you the accept and maybe an up-vote too. Commented Mar 6, 2013 at 14:37

1 Answer 1

2

Try this:

if [ $MAXseeds -lt $sumS ];
then 
  MAXseeds=$sumS
  best_file=$COUNT
fi 

Without the spaces around "=".

If you put a space after "MAXseeds", then it will be interpreted as a command. And of course, it is not a command, thus you get your error message.

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

3 Comments

hey sorry although you would be correct this is not the problem the if statement is line 34, I did not copy that bit from my code correctly there is no spaces around "=". I have updated question to reflect this as well. My script is trying to evaluate $MAXseeds as a command not a variable why is this?
@brendanmorrison: you don't show line 34; you can't expect us to debug line 34. Show us the SSCCE (Short, Self-Contained, Correct Example) version of your problem. Don't invalidate the answers that have been given. Don't expect us to work miracles — we can't debug what you don't show!
will do Jonathan, I thought editing would be simpler none the less i will add to my question and outline my exact problem as clearly what I have above should work

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.