ADVERTISEMENT
ADVERTISEMENT

Linux shell script program to demonstrate the '$#' variable

Here, we are going to demonstrate the '$#' variable in Linux shell script.
Submitted by Nidhi, on February 14, 2021

Problem Solution:

Here, we will use the "$#" variable to print the total number of command-line arguments passed and print the argument total on the console screen.

Program/Source Code:

The source code to create a Linux shell script program to demonstrate the "$#" variable is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

#!/bin/bash

# Program name: "total_command.sh"
# Linux shell script program to demonstrate the "$#" variable.
echo "Total command line arguments are: $#"

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

Output:

$ sh total_command.sh  1 2 3 4 5
Total command line arguments are: 5

Explanation:

In the above program, we used the $# variable to get the total number of the command-line argument passed. Here, we passed the argument total using the echo command 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.