DevOps/Cloud By GK
  • DevOps/Cloud Introduction
  • 🚩AWS
    • Create AWS Account
    • Launch EC2 Instance
  • 🚩Linux
    • User Managment
      • Adding the User to Sudo group
      • visudo
    • Directory / File Management
      • Vi
      • Changing Permissions (chmod)
      • Filtering IO/File
    • Memory Management
    • Process Management
    • Network Management
    • Service Management
    • Environmental Variables
      • $PATH
    • Utilities
    • SHELL PROGRAMMING
      • Hello World
      • Variables
      • Command Line arguments
      • Conditional Statements
      • Array
      • Loops
      • Functions
      • AWK
      • sed
      • Example Useful Scripts
      • Basic -> Advanced
  • 🚩git
    • Introduction
    • Creating GitHub Account
    • Installation
      • Git Bash In Windows
      • Git In VS Code
      • Git In Eclipse
      • Git CLI in Linux
  • Creating Git Remote Repository
  • Git Commands L -> R
  • Git Commands L <- R
  • Git Branch Commands
  • Using SSH (Password Less)
  • 🚩maven
    • Introduction
    • Installation
    • POM.xml
    • Goals
  • 🚩SonarQube
    • Introduction
    • Sonar Cloud
    • Creating Project In SonarCloud
    • Installing Sonar-Scanner
    • Triggering Scan
  • 🚩Nexus
    • Introduction
    • Installation of Nexus
    • Creating Repository
    • Uploading Artifacts to Repository
  • 🚩Jenkins
    • Introduction
    • Installation of Jenkins
    • First Job In Jenkins
    • Git + Jenkins
      • WebHook
    • Maven + Jenkins
    • Sonar-Scanner + Jenkins
    • Nexus + Jenkins
Powered by GitBook
On this page
  1. Linux
  2. SHELL PROGRAMMING

Variables

Here's an example of a shell script that demonstrates variable usage:

#!/bin/bash

# Variable assignment
name="John"
age=30

# Accessing variables
echo "Name: $name"
echo "Age: $age"

# Modifying variables
name="Jane"
age=$((age + 5))

echo "Modified Name: $name"
echo "Modified Age: $age"

# Command substitution
current_date=$(date +%Y-%m-%d)
echo "Current Date: $current_date"

In this script, we have the following variable-related operations:

  • Variable Assignment: We assign values to the name and age variables using the syntax variable_name=value. For example, name="John" assigns the string "John" to the name variable, and age=30 assigns the number 30 to the age variable.

  • Accessing Variables: We use the echo command to display the values of the name and age variables. By using the $ prefix ($name, $age), we access the values stored in those variables.

  • Modifying Variables: We modify the values of the name and age variables. We assign a new value to name ("Jane") and update age by adding 5 to its current value using arithmetic expansion ($((expression))).

  • Command Substitution: We use the $(command) syntax to perform command substitution. In this example, we use the date command with the +%Y-%m-%d format specifier to get the current date and store it in the current_date variable.

When you run the script, it will display the initial values of name and age, then the modified values after the variable updates. Finally, it will print the current date obtained through command substitution.

PreviousHello WorldNextCommand Line arguments

Last updated 2 years ago

🚩