You are not logged in.

#1 2005-11-21 00:47:11

z4ziggy
Member
From: Israel
Registered: 2004-03-29
Posts: 573
Website

expanding parameters in bash

hey,

im trying to pass to a bash procedure my command line parameters, and im using "set" command to expand the parameters. however, i dont want it to break parameters which are inclused with double-quotes and separated by spaces. here is a test case :

#!/bin/bash
test()
{
        set $*
        echo p1=$1
        echo p2=$2
}
echo p1=$1
echo p2=$2
echo ---
test $*

test case result:

[ziggy@localhost]# ./test 1 "2 3"
p1=1
p2=2 3
---
p1=1
p2=2

as you can see, the formatting of the command line is perfect, but the test() procedure breaks it. any way of accomplishing the same in the test() procedure?

thanks.

Offline

#2 2005-11-21 02:16:59

alterkacker
Member
From: Peoples Republic of Boulder
Registered: 2005-01-08
Posts: 52

Re: expanding parameters in bash

#!/bin/bash
test()
{
        set "$@"
        echo p1=$1
        echo p2=$2
}
echo p1=$1
echo p2=$2
echo ---
test "$@"

The "$@" preserves "2 3" as a single 'word'.

Offline

#3 2005-11-21 06:23:35

z4ziggy
Member
From: Israel
Registered: 2004-03-29
Posts: 573
Website

Re: expanding parameters in bash

thanks man smile

Offline

Board footer

Powered by FluxBB