LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   About positional parameters (https://www.linuxquestions.org/questions/linux-newbie-8/about-positional-parameters-4175558107/)

sleftar 11-05-2015 03:26 PM

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.

berndbausch 11-05-2015 06:08 PM

You just use "shift 2" to get rid of the first two parameters.

Reference

sleftar 11-06-2015 02:12 AM

Oh man many thanks :E

grail 11-06-2015 03:20 AM

Or maybe remember that '@' is essentially an array:
Code:

echo ${@:3}

sleftar 11-06-2015 05:08 AM

Quote:

Originally Posted by grail (Post 5445470)
Or maybe remember that '@' is essentially an array:
Code:

echo ${@:3}

what does echo ${@:3} exactly mean?

sleftar 11-06-2015 05:51 AM

Quote:

Originally Posted by grail (Post 5445470)
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 .


All times are GMT -5. The time now is 08:06 AM.