0% found this document useful (0 votes)
10 views8 pages

Shell Scripting in Linux

Uploaded by

titaniumgamer67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Shell Scripting in Linux

Uploaded by

titaniumgamer67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Shell scripting in Linux

• Shell scripting in Linux involves writing a series of commands in a


script file, which can then be executed to perform tasks automatically.
• Shell scripts are powerful for automating repetitive tasks, managing
system processes, and configuring network settings.
• 1. Basic Structure of a Shell Script
• A shell script starts with a "shebang" line, which tells the system
which interpreter to use. Here’s the structure of a simple script:
• #!/bin/bash
• # This is a comment
• echo "Hello, World!" # Print Hello, World! to the screen
• Save this script with a .sh extension (e.g., hello.sh) and make it
executable:
• 2. Variables
• You can define variables without any special symbols, and access
them using the $ symbol.
• #!/bin/bash
• name="Alice"
• echo "Hello, $name"
• 3. User Input
• Read input from the user with the read command:
• #!/bin/bash
• echo "Enter your name:"
• read name
• echo "Hello, $name!"
• 4. Conditionals
Use if statements to make decisions:

• bash
• Copy code
• #!/bin/bash
• echo "Enter a number:"
• read number

• if [ $number -gt 10 ]; then


• echo "The number is greater than 10"
• else
• echo "The number is 10 or less"
• fi
• 5. Loops
• Loops allow you to repeat actions multiple times.

• For Loop
• #!/bin/bash
• for i in 1 2 3 4 5;
• do
• echo "Number $i“
• done
• While Loop
• #!/bin/bash
• count=1
• while [ $count -le 5 ];
• do
• echo "Count: $count" ((count++))
• done

You might also like