Created on: 2025-02-02 Tags: #ShellScripting Course:HPC
Definition
A shell-script is a file containing a series of commands that are executed by the shell.
Shell: The command interpreter in Linux
Use Cases: Automating repetitive task, system monitoring, batch processing, etc.
Different kinds of Linux shells: Bash, sh, Zsh, Dash, etc.
Creation and Running Shell Scripts
Creation of a .sh file in any text editor.
Add the Shebang (#!/bin/bash) -> Type of shell used.
Make the file executable using chmod.
Run the script by running the executable ./fileName.sh
Variables and Input/Output
Declare the variable and use it with $. Example
1
2
name='Picther'
echo "My name is $name"
Listing all the environment variables: env
Set the environment variables: export var=value
Within script there is no difference in locally declaring a variable and exporting an environment variable.
Locally declared variable is available only for the current shell session only, but not for child processes. While environment variables are available for child processes. ```sh !/bin/bash name1=”Rakesh” export name2=”Mahesh”