ADVERTISEMENT
ADVERTISEMENT

Linux shell script program to print program name using command line argument

Here, we are going to learn how to print program name using command line argument in Linux shell script?
Submitted by Nidhi, on February 14, 2021

Problem Solution:

Here, we will create a shell script program to print program name using the $0 variable on the console screen.

Program/Source Code:

The source code to create a Linux shell script program to print program name using command-line argument is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

#!/bin/bash
# Program name: "script_name.sh"
# shell script program to print program name using command line argument.
echo "Script program Name: $0"

Now, we will save the shell script program with the "script_name.sh" name.

Output:

$ sh script_name.sh 
Script program Name: script_name.sh

Explanation:

Here, we used the $0 variable to print the program name on the console screen.

Linux shell script programs »

ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.