Passing arguments to a shell script

Any shell script you run has access to (inherits) the environment variables accessible to its parent shell. In addition, any arguments you type after the script name on the shell command line are passed to the script as a series of variables.

The following parameters are recognized:


$*
Returns a single string (``$1, $2 ... $n'') comprising all of the positional parameters separated by the internal field separator character (defined by the IFS environment variable).

$@
Returns a sequence of strings (``$1'', ``$2'', ... ``$n'') wherein each positional parameter remains separate from the others.

$1, $2 ... $n
Refers to a numbered argument to the script, where n is the position of the argument on the command line. In the Korn shell you can refer directly to arguments where n is greater than 9 using braces. For example, to refer to the 57th positional parameter, use the notation ${57}. In the other shells, to refer to parameters with numbers greater than 9, use the shift command; this shifts the parameter list to the left. $1 is lost, while $2 becomes $1, $3 becomes $2, and so on. The inaccessible tenth parameter becomes $9 and can then be referred to.

$0
Refers to the name of the script itself.

$#
Refers to the number of arguments specified on a command line.


Top Online Courses From ProgrammingKnowledge
Python Programming Course Programming Course Shell Scripting Course Command Line Tutorials Programming Course Programming Course Programming Course Development Course Programming Course Programming Course Programming Course Course For Developers and DevOps Programming Tutorial Course Responsive Web Design Tutorial Tutorial Course C++ GUI Tutorial For Beginners Online Courses to learn
Get 2 FREE Months of Unlimited Classes from skillshare - https://skillshare.eqcm.net/r1KEj
Data Science - | Learning - |
Artificial Intelligence - | Stack E-Degree Program - | E-degree - | Analytics with R - | Certification Training - | in Java - | Learning With TensorFlow - | 8 - Complete Essential Guide - Android Development Masterclass - iOS Programming Building Advance Projects - Follow
My Website - http://www.codebind.com

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!