LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:30 PM   #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, 12:51 PM   #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, 01: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,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
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, 06: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 06:23 PM.
 
Old 03-21-2011, 10:30 PM   #5
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 8,250

Rep: Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558Reputation: 1558
"Positional parameter" is another term for "command line arguments."
 
Old 03-22-2011, 03: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, 09: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:03 PM
Why we should give "core" parameter in yum config file ram_rajavarapu Linux - Enterprise 2 08-16-2010 01:49 PM
getting "parameter has incomplete type" and "conflicting types" error yogi.aash Linux - Newbie 2 05-31-2010 07:25 PM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 07:15 PM
[SOLVED] How can I fix "Error: BadWindow (invalid window parameter)" ShellyCat Linux - Desktop 1 08-17-2007 10:42 AM


All times are GMT -5. The time now is 07:30 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration