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 11-05-2015, 03:26 PM   #1
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Rep: Reputation: Disabled
About positional parameters


Hi guys,

I know few tricks about positional parameters..

For example

Code:
set Joshua is my name.
echo $@
echo "$3 $4"
first one prints everything and second will print the part "my name."

Is there any way to write the second echo except this one.. For example I want all positional parameters to be printed except first 2.

I mean what I want to write is instead of writing this

Quote:
echo "$3 $4"
Is there any way to write it as for example

Quote:
echo "$@-($1+$2)"
because I want user to enter that sentence for me and I dont want my program to take first 2 positional parameters but I want computer to take rest of all parameters... Thanks.

Last edited by sleftar; 11-05-2015 at 03:27 PM.
 
Old 11-05-2015, 06:08 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You just use "shift 2" to get rid of the first two parameters.

Reference
 
1 members found this post helpful.
Old 11-06-2015, 02:12 AM   #3
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Oh man many thanks :E
 
Old 11-06-2015, 03:20 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Or maybe remember that '@' is essentially an array:
Code:
echo ${@:3}
 
Old 11-06-2015, 05:08 AM   #5
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Or maybe remember that '@' is essentially an array:
Code:
echo ${@:3}
what does echo ${@:3} exactly mean?
 
Old 11-06-2015, 05:51 AM   #6
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Or maybe remember that '@' is essentially an array:
Code:
echo ${@:3}
nvm I got it.. Similar thing but this time does not really change $@ itself. Takes whole parameters starting from 3rd element of the array.. This one would be more useful since you may also want to keep first 2 elements of the array to use somewhere else although I dont need first 2 elements for my example I took this to my notes since I can use at some point.Thanks .

Last edited by sleftar; 11-06-2015 at 06:46 AM.
 
  


Reply



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
[SOLVED] Need Help with Positional Parameters gdizzle Programming 3 05-20-2015 10:38 PM
perl positional parameters/ casperdaghost Programming 6 11-11-2011 01:08 AM
shell: positional parameters... neidias Programming 1 04-04-2005 02:45 PM
Positional Parameters (arguments) desbyleo Solaris / OpenSolaris 2 10-25-2004 11:51 AM
Help with positional parameters Read_Icculus Linux - General 7 11-02-2003 04:23 AM

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

All times are GMT -5. The time now is 08: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