Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Bash syntax question
- To: tlug@example.com
- Subject: Re: [tlug] Bash syntax question
- From: Frank Bennett <bennett@example.com>
- Date: Wed, 30 Jan 2002 17:05:52 +0900
- Content-disposition: inline
- Content-type: text/plain; charset=euc-jp
- In-reply-to: <20020130060350.GA737@example.com>
- References: <20020130060350.GA737@example.com>
- User-agent: Mutt/1.3.25i
On Wed, Jan 30, 2002 at 03:03:50PM +0900, Frank Bennett wrote: > I want to pass a set of array values to a function in a Bash script. I've worked out a solution to this that only makes me feel a little bit sick when I have to look at it. The trick seems to be put some character that is not used in the expanded text at the start of the IFS delimiter variable. Here's an irritating demo: #!/bin/bash function ask_questions () { LOCAL_ARRAY=($1) shift PUBLIC_ARRAY=("${QUESTIONS[@]}") echo === Assignment via parameter === for i in "${LOCAL_ARRAY[@]}"; do echo "${i}" $1 done echo === Assignment from global variable === for i in "${PUBLIC_ARRAY[@]}"; do echo "${i}" $1 done } echo ================================== echo Trial 1: IFS left at default value echo ================================== QUESTIONS=("1. WHY?" "2. REALLY, WHY?" "3. WELL?") ask_questions "${QUESTIONS[*]}" Huh? echo ====================================== echo Trial 2: IFS set to TAB for assignment echo ====================================== IFS=$'\t' QUESTIONS=("1. WHY?" "2. REALLY, WHY?" "3. WELL?") ask_questions "${QUESTIONS[*]}" Huh?
- Follow-Ups:
- Re: [tlug] Bash syntax question
- From: Frank Bennett
- References:
- [tlug] Bash syntax question
- From: Frank Bennett
Home | Main Index | Thread Index
- Prev by Date: [tlug] pcg-c1mrx / pcg-c1mv
- Next by Date: Re: [tlug] Bash syntax question
- Previous by thread: [tlug] Bash syntax question
- Next by thread: Re: [tlug] Bash syntax question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links