Receive all updates via Facebook. Just Click the Like Button Below

Command Line Arguments in Shell Scripts

The command line arguments are important in shell scripts.
This help users to pass values directly to the script using command line.

1

Command Line Arguments in Linux Shell Scripting

2

Reading command line arguments

Lets try it with an example script: cmd-line-arg.sh

 
#!/bin/sh
# Script that demos, command line args
echo "Total number of command line argument are $#"
echo "$0 is script name"
echo "$1 is first argument"
echo "$2 is second argument"
echo "All of them are :- $* (or) $@"
          

Running the script: cmd-line-arg.sh
chmod 755 cmd-line-arg.sh
./cmd-line-arg.sh 1 2 3 4 last
Total number of command line argument are 5
./cmd-line-arg.sh is script name
1 is first argument
2 is second argument
All of them are :- 1 2 3 4 last (or) 1 2 3 4 last

Important:
$* (or) $@ can be used to print or read all the command line arguments.
$1 is the first argument, $2 the second, $3 the third and so on.

3

Related posts:

Advertise here

picture picture

Follow us

picture

- Tech-Tutorials twitter.com/techcuriosity

Like us

About Techcuriosity

I am Telson, the webmaster of Techcuriosity.com and through this site, I share my knowledge and curiosities in the Tech World.


What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch

    techcuriosity@gmail.com
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture

    picture