0

I have a list formatted as below. If I replace the list by, say, "aaa bbb ccc", everything works fine. Anyone an idea?

list=$(echo -e "1.1 1.2 mgmt")

n=0
for i in $list; do
   let "array1_$i[$n]=$(date "+%N")"
   ((++n))
done

n=0
for i in $list; do
   var=array1_$i[$n]
   echo ${!var}
   ((++n))
done

thanks in advance for any ideas...

2 Answers 2

1

You can change the shebang line to

#!/bin/bash -xv

to see what bash tries to run. In fact, you are trying to create a variable named array1_1.1, which is not a valid variable name: dots are not allowed.

Sign up to request clarification or add additional context in comments.

1 Comment

I am amazed at the usefulness of that information. I can see what bash tries to run? UPVOTE. (On investigation, -xv also works for dash (my favored shell for scripts that have to run really fast), zsh, ksh and possibly all other major sh-variants.)
1

. is not a valid character in an identifier.

man bash:

       name   A word consisting only of alphanumeric characters and underscores, and
              beginning with an alphabetic character or an underscore.  Also
              referred to as an identifier

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.