>_ IzzyLab

Topic breakdown

Finding the maximum is a classic "best so far" algorithm: you keep the current record and update it when you meet a bigger number. A file is read line by line with a while loop using the read command and redirecting the file into the loop's input — on each iteration the next line lands in the variable. Integers in a [ ... ] test are compared with the -gt operator (not >, which there means redirection). An important detail is initialization: an empty starting record breaks the first comparison, so as the start you take either a deliberately small value or the first number read.

What's checked

  1. max.txt has the largest number from nums.txt
  2. max.sh finds the maximum from the file contents (mixed signs)
  3. max.sh works when all numbers are negative

What it looks like