Skip to main content

Bash Programming Tutorial - Argument Handling

Hello Friends,

Welcome Again To My Blog. Today, I am going To Share With You A Simple Bash Script. This Script Will Demonstrate How Bash Script Can Access User Pass Parameters Using Simple Variables And How Can Get Environment Variables.

This Bash Script is really very to Understand and By The Way, For Completely New Bies, I had Used Good Comments Lines To Make This Script More Easy To Understand.

To Run This Script

chmod +x


Bash Command Line Parameters Handling Script

# Author :
# Suraj Singh Bisht
# ====================================================
#         Please Don't Remove Author name
# ====================================================
# Description:
#  Script To Play With Command Line Parameters Inputs

# To Print Home Directory Path
printf "This is Our Home Directory  : %s\n" $HOME

# To Print Current Working Directory Path
printf "This is Current Working Path : %s\n" $PWD

# Print All Environment Path
printf "Environment Path   : %s\n" $PATH

# Numbers of Arguments Pass
printf "Numbers Of Arugments  : %d\n" $#

# Iterate All Passed Arguments
printf "All Arguments In One Variable[1]: %s\n" $*
printf "All Arguments In One Variable[2]: %s\n" $@

# Name Of Current Script
printf "Name Of Current Script  : %s\n" $0

# Current Process PID Numbers
printf "Process Id Number(PID)  : %d\n" $$

# Previous Executed Program Exit Code
printf "Exit Code of Previous Program : %d\n" $?

# Last Argument Passed Through Command Parameters
printf "Last Argument    : %s\n" $_

# Previous Execute Process Identity numbers
printf "Previous Command PID Number : %d\n" $!

 For More Updated Example, Check Github Here

Related Post

Top Visited

Big List Of Google Dorks For Sqli Injection

List of Keyboard Shortcuts Keys for GNOME Desktop (Kali linux / Linux / Ubuntu/*nix )

Create Simple Packet Sniffer Using Python

how to install burp suite in Linux/Ubuntu 16.04

How to create Phishing Page Using Kali Linux | Webpage Page Cloning Using Kali Linux Social Engineering Toolkit

Best 1000 User-agents List For Web Scraping

How To Install GDB Peda?

Latest Google Dorks List

2 Easiest Way To Enable Monitor Mode in Kali Linux | Airmon-ng | Iwconfig

How To Create Snake Game Using Python And Tkinter - Simple python games