Home »
Linux »
Linux shell script programs
Linux shell script program to print program name using command line argument
By IncludeHelp Last updated : October 20, 2024
Problem statement
Here, we will create a shell script program to print program name using the $0 variable on the console screen.
Print program name using command line argument
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.
Linux shell script program to print program name using command line argument
#!/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 »