[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Comparing Korn Shell Variables

Posted on 2012-09-14
Medium Priority
Last Modified: 2012-09-14
Is there a simple way to compare the value of two Korn shell variables, and when the value of the second is larger, assign that value to the first? So, if the value of VAR2 is greater than the value of VAR1, set VAR1 equal to VAR2.
Question by:babyb00mer
  • 2
LVL 68

Expert Comment

ID: 38400303
For a numeric comparison:

[[ $VAR2 -gt $VAR1 ]] && VAR1=$VAR2

For a string comparison:

[[ "$VAR2" > "$VAR1" ]] && VAR1="$VAR2"

"man test" explains all test operators.

Author Comment

ID: 38400366
Yep, that would do it. Do I feel stupid. I guess I was just feeling lazy today. :-)
LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 38400379
Don't worry, it's Friday!



Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question