LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 03-21-2011, 11:30 AM   #1
Ribo01
Member
 
Registered: Aug 2010
Posts: 103

Rep: Reputation: 5
what is "positional parameter" ?


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.
 
Old 03-21-2011, 11:51 AM   #2
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
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.
 
1 members found this post helpful.
Old 03-21-2011, 12:03 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Positional parameters are a series of special variables ($0 through $9) that contain the contents of the command line.

Go read http://linuxcommand.org/wss0130.php to get a clearer idea of what they're all about (full of examples).

Hope this helps some.
 
Old 03-21-2011, 05:18 PM   #4
Ribo01
Member
 
Registered: Aug 2010
Posts: 103

Original Poster
Rep: Reputation: 5
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?

Last edited by Ribo01; 03-21-2011 at 05:23 PM.
 
Old 03-21-2011, 09:30 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
"Positional parameter" is another term for "command line arguments."
 
Old 03-22-2011, 02:10 AM   #6
Ribo01
Member
 
Registered: Aug 2010
Posts: 103

Original Poster
Rep: Reputation: 5
Thanks to all, think I got it now. U guys are the best. Lovely day ahead. Cheers.
 
Old 03-22-2011, 08:41 AM   #7
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by frankbell View Post
"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.
 
  


Reply

Tags
command line, parameter



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shifting positional parameter inside a function rylphs Linux - Newbie 9 10-19-2010 01:03 PM
Why we should give "core" parameter in yum config file ram_rajavarapu Linux - Enterprise 2 08-16-2010 12:49 PM
getting "parameter has incomplete type" and "conflicting types" error yogi.aash Linux - Newbie 2 05-31-2010 06:25 PM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
[SOLVED] How can I fix "Error: BadWindow (invalid window parameter)" ShellyCat Linux - Desktop 1 08-17-2007 09:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration