Shell script in Linux in Hindi

Shell scripts Unix-like operating systems mein tasks automate karne aur custom functions define karne ke liye istemal hoti hain. Niche diye gaye steps shell scripts likhne aur execute karne ke liye hain, sath hi parameter substitution, shell variables, aur standard shell variables ke bare mein bhi bataya gaya hai:

Shell script in Linux in Hindi

Shell Script Likhein aur Execute Karein:

  1. Shell Script Ka File Create Karein:
  • Shell script ko create karne ke liye text editor ka istemal karein aur script ko .sh extension ke sath save karein, jaise ki myscript.sh.
  1. Script Mein Shebang Line Add Karein:
  • Script ke shuruwat mein ek shebang line add karein jo shell ko specify karti hai, jaise ki #!/bin/bash (Bash shell ke liye).
  1. Script Mein Commands Likhein:
  • Script mein aapko jo bhi commands aur tasks automate karna hai, unhe likhein. For example:
   #!/bin/bash
   echo "Hello, World!"
  1. Script Ko Execute Karein:
  • Script ko execute karne ke liye command line mein ./myscript.sh type karein, jahan myscript.sh aapke script ka filename hai.
  • Script ko execute karne se pehle usko executable permission dena hoga. chmod +x myscript.sh se script ko executable banaya ja sakta hai.

Parameter Substitution:

Shell scripts mein aap parameter substitution ka istemal karke variables aur arguments ke sath kaam kar sakte hain.

  • $0: Script ka naam (example: myscript.sh).
  • $1, $2, $3, …: Positional parameters, yani script ko diye gaye arguments (example: ./myscript.sh arg1 arg2 mein $1 arg1 ko represent karega).
  • $#: Number of arguments.
  • $@: Saare arguments ko ek string mein.
  • $*: Saare arguments ko ek string mein lekin alag-alag quotation marks ke sath.
  • $?: Last command ka exit status.
  • $$: Current shell ka process ID.

Shell Variables:

Aap script ke andar apne custom variables bhi define kar sakte hain.

#!/bin/bash
name="John"
age=30
echo "My name is $name and I am $age years old."

Standard Shell Variables:

Shell scripts mein kuch standard variables predefined hoti hain:

  • $HOME: Current user ka home directory.
  • $USER: Current user ka username.
  • $PWD: Current working directory.
  • $SHELL: Current user ka default shell.

Yeh variables aapke scripts mein use karke system information aur user context ke sath kaam kar sakte hain.

Shell scripts likhna aur execute karna ek powerful tareeka hai Unix-like systems par tasks automate karne ka. Aap in scripts mein parameter substitution, custom variables, aur standard shell variables ka istemal karke apne tasks ko customize kar sakte hain.

Leave a Comment