Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:46:58+00:00 2026-05-26T23:46:58+00:00

I am writing a script that finds the minimum value in a string. The

  • 0

I am writing a script that finds the minimum value in a string. The string is given to me with a cat <file> and then I parse each number inside that string. The string only contains a set of numbers that is separated by spaced.

This is the code:

echo $FREQUENCIES
for freq in $FREQUENCIES
do
    echo "Freq: $freq"
    if [ -z "$MINFREQ" ]
    then
        MINFREQ=$freq
        echo "Assigning MINFREQ for the first time with $freq"
    elif [ $MINFREQ -gt $freq ]
    then
        MINFREQ=$freq
        echo "Replacing MINFREQ with $freq"
    fi
done

Here is the output I get:

800000 700000 600000 550000 500000 250000 125000 
Freq: 800000
Assigning MINFREQ for the first time with 800000
Freq: 700000
Replacing MINFREQ with 700000
Freq: 600000
Replacing MINFREQ with 600000
Freq: 550000
Replacing MINFREQ with 550000
Freq: 500000
Replacing MINFREQ with 500000
Freq: 250000
Replacing MINFREQ with 250000
Freq: 125000
Replacing MINFREQ with 125000
Freq: 
: integer expression expected

The problem is that the last line, for some reason, is empty or contain white spaces (I am not sure why). I tried testing if the variable was set: if [ -n “$freq” ] but this test doesn’t seem to work fine here, it still goes through the if statement for the last line.

Could someone please help me figure out why the last time the loop executes, $freq is set to empty or whitespace and how to avoid this please?

EDIT:

using od -c feeded with echo "<<$freq>>"

0000000   <   <   8   0   0   0   0   0   >   >  \n
0000013
0000000   <   <   7   0   0   0   0   0   >   >  \n
0000013
0000000   <   <   6   0   0   0   0   0   >   >  \n
0000013
0000000   <   <   5   5   0   0   0   0   >   >  \n
0000013
0000000   <   <   5   0   0   0   0   0   >   >  \n
0000013
0000000   <   <   2   5   0   0   0   0   >   >  \n
0000013
0000000   <   <   1   2   5   0   0   0   >   >  \n
0000013
0000000   <   <  \r   >   >  \n
0000006

There seems to be an extra \r (from the file).

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:46:59+00:00Added an answer on May 26, 2026 at 11:46 pm

    If you’re only working with integer values, you can validate your string using regex:

    elif [[ $freq =~ ^[0-9]+$ && $MINFREQ -gt $freq ]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Perl script (in Windows) that is using File::Find to index
I'm writing a script that has to move some file around, but unfortunately it
I am writing a script that checks if given domain is parked or not.
I am writing a script that is retrieving information from file places.sqlite (history) and
I have recently finished writing a script for Maya that exports a file containing
I am writing a Perl script that is iterating over file names in a
I'm writing a php script that will fetch data from a given URL and
I am writing a script that will look in a custom reports directory, copy
I'm writing a script that will ping my ip range. Here's what I have
I'm writing a script that'll read through my ftpd logs and generate a hash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.