Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Bash syntax question



Here's a better solution that takes advantage of Bash 2.0 indirect assignment.
All of the clutter is now concealed inside the function.

(Just in case I'm at risk of being flamed for this series of messages, this
is for shoehorning workable gettext support into a shell script.  Finished
functionality available on request.  :-)

#!/bin/bash
function ask_questions () {
  local IFS
  IFS=$'\t' 
  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
}

QUESTIONS=("1. WHY?" "2. REALLY, WHY?" "3. WELL?")

ask_questions "QUESTIONS[*]" Huh?


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links