Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»How to declare boolean variable in shell script

    How to declare boolean variable in shell script

    RahulBy RahulJuly 25, 20221 Min ReadUpdated:July 25, 2022

    The shell (bash) script doesn’t offer any data type with the variables. So we can’t specifically declare a variable of type boolean in shell scripts.

    But, you can still use the variable like a boolean in shell scripts. Store a sample string “true” to a variable and match it with the if condition. This works similarly to boolean.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #!/usr/bin/env bash
     
    # Assign a string to a variable
    var=true
     
    # Test the variable value
    if [ "$var" = 'true' ]; then
       echo "It's true"
    else
       echo "It's false"
    fi

    So, even if the shell script doesn’t offer the data types, but we can still use the normal variable with similar working.

    shell script variable
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Create Branch in Git Repository
    Next Article YYYY-MM-DD format date in a Shell Script

    Related Posts

    How to Import GPG Keys on Ubuntu & Debian (without apt-key)

    2 Mins Read

    Running a Cron job every Sunday (Weekly)

    2 Mins Read

    Scheduling a Python Script with Crontab

    2 Mins Read

    Running cron job every 12 hours (twice a day)

    Updated:August 2, 20221 Min Read

    How to run a command on bash script exits

    1 Min Read

    (Resolved) Key is stored in legacy trusted.gpg Keyring

    Updated:August 9, 20222 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.