About 458,000 results
Open links in new tab
  1. How to compare strings in Bash - Stack Overflow

    Feb 10, 2010 · The following script reads from a file named "testonthis" line by line and then compares each line with a simple string, a string with special characters and a regular …

  2. shell - How can I compare numbers in Bash? - Stack Overflow

    If you want to compare float numbers or float number to integer, you can use (( $(bc <<< "...") )). For example, a=2.00 b=1 if (( $(bc <<<"$a > $b") )); then echo "a is greater than b" else echo …

  3. How to Compare Numbers and Strings in Linux Shell Script

    Sep 13, 2020 · Tutorial on how to compare numbers, strings and files in Linux bash shell script using if statement.

  4. How do I compare two string variables in an 'if' statement in Bash?

    The main difference lies in which scripting language you are using. If you are using Bash then include #!/bin/bash in the starting of the script and save your script as filename.bash. To …

  5. Bash script: String comparison examples - LinuxConfig

    In this tutorial, we’ll show you how to compare strings in a Bash script on a Linux system. We’ll show this in the context of a simple if/else Bash script so you can see how testing for this …

  6. How to compare two strings (from user input) in a bash script

    Nov 29, 2015 · Unless you have to use cmp, you can use [ ] for comparison: echo "Both words contents are same" echo "Both words contents are not same" cmp compares files. If, say, you …

  7. How to Compare Strings in Bash With If Statement [6 Methods]

    Jan 10, 2024 · To compare strings in bash, there are some comparison operators such as =, <, ==, >, !=, -z, -n. In addition, Case statements can be used to perform string comparisons. In …

  8. How to Compare Strings in Bash - Linuxize

    May 3, 2019 · When comparing strings in Bash you can use the following operators: string1 = string2 and string1 == string2 - The equality operator returns true if the operands are equal. …

  9. Compare Variables With Numbers in Bash | Baeldung on Linux

    Mar 25, 2025 · As Linux users, there will be times when we need to write a script to perform a certain task and iterate the script based on certain numeric conditions. In such cases, we use …

  10. Compare string in BASH - LinuxConfig

    Sep 24, 2020 · In this guide, we saw how to compare strings in Bash, both from command line and in if/else Bash scripts. This functionality can, of course, be extended to more robust scripts …

Refresh