I am trying make a script that combines arrays on demand. Here is the script:
#! /bin/bash
declare -A code
code=( [H]="h" [E]="e" [L]="l" [P]="p" [M]="m" [E]="e" )
I need to print "help me" - without quotes and in one line - when I enter ./filename.bash "HELP ME" at command prompt. here is what I am using.
code=$1;
for (( i = 0; i < ${#code[@]} ; i = $i + 1 ));
do;
echo ${code[@]:$i:1};
done
$1
? you should be iterating over$1
, using each of its characters to index into yourcode
array, surely? – steeldriver May 11 '15 at 0:52tr "a-zA-Z" "A-Za-z" <<<"HELP ME"
– and, regarding associative arrays, you can use a space for the index[' ']=' '
(if it helps). – Peter.O May 11 '15 at 4:39tr "EHLMP" "ehlmp" <<< "HELP ME"
– Cyrus May 11 '15 at 5:00