Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hello y'all, I need a simplistic explanation of positional parameter. Have read all I can get my hands in, I kinds of understand to an extent, but I want to get. Full grasp of it. Oils like to know what is does, its functions, when to use it, and all its functions. Thanks in anticipation. Distro Red hat.
A positional parameter is a parameter whose position on the command line is important to the program reading it.
For example, the cp command format: cp [options] [source] [destination]
The options are positional parameters, as they must immediately follow the cp command to be interpreted correctly by the cp program. The source and destination parameters are also positional parameters... if you reverse their order, you won't get the results you were expecting.
If the cp program did not use positional parameters, it would be necessary to identify your parameters to it in another way, like so: cp --options[options] --source[source] --target[target]
In this fictional example, since all of the options have something identifying them, you could change the order without impact.
In Linux, it's very easy to use positional parameters compared to non-positional, because any command-line arguments automatically get assigned to a variable $1, $2, $3, etc., depending on the order they're supplied on the command line.
To sl00b, correct me if am wrong. So basically, what you are telling me from your post is that positional parameter are the options that comes immediately after any command issued right?and does its work the same way in shell scripting?
"Positional parameter" is another term for "command line arguments."
Sorry, but you are grossly oversimplifying here. In general, you are correct, but only because it's so easy to use positional parameters in Linux commands, and so commands most do. But there are too many situations where they do not.
Consider the java command. With so many different combinations of arguments, it's impossible to make them positional... and so, they're not.
If an argument's position on the command line is sufficient to identify it to the program it's sent to, it's a positional parameter. If, on the other hand, it can appear anywhere on the command line, because the program has got extra intelligence built into it to interpret the command line, then it's not positional.