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 path_to_script.sh

./path_to_script.sh


Bash Command Line Parameters Handling Script



#!/bin/bash
#
#
# Author :
# Suraj Singh Bisht
# surajsinghbisht054@gmail.com
# www.bitforestinfo.com
# github.com/surajsinghbisht054
#
#
# ====================================================
#         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

Create Simple Packet Sniffer Using Python

how to install burp suite in Linux/Ubuntu 16.04

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

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

Big List Of Google Dorks For Sqli Injection

Latest Google Dorks List

Best 1000 User-agents List For Web Scraping

How To Install GDB Peda?

What is the use of Pseudo header in TCP/UDP packets?

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