You are not logged in.

#1 2008-08-29 02:00:16

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

[SOLVED] BASH ${unlimited arguments}

When programming in BASH, you may use the syntax '$1 $2 $3 ...' to specify which token/argument you want to do something with.  Is there an existing function that allows for unlimited argument selection?  I'm looking for something along the lines of this:

~$ cat MY_SCRIPT
#!/bin/bash
echo ${unlimited arguments}
~$ bash MY_SCRIPT cat dog horse
cat dog horse

Edit: Please forgive my rudimentary BASH skills smile

Last edited by deltaecho (2008-08-29 10:41:57)


Dylon

Offline

#2 2008-08-29 02:37:57

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: [SOLVED] BASH ${unlimited arguments}

#!/bin/bash
echo $*

Here is a very useful bash guide for you: http://tldp.org/LDP/abs/html/

Offline

#3 2008-08-29 02:41:17

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] BASH ${unlimited arguments}

If you want to do something with each argument, you could use this:

#!/bin/bash
for ARG in "$@"
do
    echo $ARG
done

Last edited by Xyne (2008-08-29 02:42:35)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2008-08-29 02:43:55

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Re: [SOLVED] BASH ${unlimited arguments}

Awesome!  That's exactly what I was looking for, thanks!


Dylon

Offline

Board footer

Powered by FluxBB