User define variables in Linux in Hindi

User-defined variables shell scripts mein khud define kiye gaye variables hote hain jo script ke execution context mein use hote hain. Aap in variables mein data store kar sakte hain aur unka istemal script ke kisi bhi hisse mein kar sakte hain. Yahan kuch tarike hain user-defined variables ko shell scripts mein define karne ke:

User define variables in Linux in Hindi

1. Variables Define Karne ka Syntax:

  • Shell scripts mein variables define karne ke liye variable name aur uske value ke beech mein ek equal sign = ka istemal hota hai.
  • Variable name ke liye alphanumerics aur underscores (_) ka istemal kiya ja sakta hai, lekin number se start nahi karna chahiye.
  • Variable value ko double quotes (” “) ya single quotes (‘ ‘) mein wrap kiya ja sakta hai, lekin double quotes mein variables expand honge, jabki single quotes mein nahi honge.

2. Examples of User-Defined Variables:

#!/bin/bash

# User-defined variables
name="John"
age=30
city="New York"

# Displaying variables
echo "Name: $name"
echo "Age: $age"
echo "City: $city"

3. Variables Ka Istemal:

  • Variables ka istemal script mein unke names ko use karke hota hai, jaise ki $name, $age, aur $city hamare example mein.
  • Variables ke values ko read aur modify kar sakte hain script ke andar.

4. Variables Ka Update:

# Existing variable ko update karna
age=31

# Variable ko append karna
city="$city, USA"

5. Read User Input:

Aap user-defined variables mein user se input bhi read kar sakte hain:

#!/bin/bash

# User input
echo -n "Enter your name: "
read name

# Displaying user input
echo "Hello, $name!"

User-defined variables shell scripts mein flexibility aur customization add karte hain, jisse aap apne tasks aur automation ko customize kar sakte hain. Isse aap script ke behavior ko change kar sakte hain aur dynamic values ko store aur use kar sakte hain.

Leave a Comment