LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 04:26 PM   #1
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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 04:27 PM.
 
Old 11-05-2015, 07:08 PM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,692

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

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

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

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

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, 06:51 AM   #6
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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 07:46 AM.
 
  


Reply


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

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

All times are GMT -5. The time now is 10:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration