1

Is there any possibility to get value from BASH array using index defined in AWK?

Bash:
table=(a b c d e)
instructions | awk " BEGIN {index=0} {print \"${table[**index**]}\"; index++} "
1
  • 1
    It sounds like you're asking us how to implement something that you shouldn't be doing. I recommend you post a different question asking how to do whatever the text transformation is that you are attempting, including sample input and expected output. Commented Oct 1, 2015 at 13:28

1 Answer 1

3

You can do this but why?

table=(a b c d e); awk -vt="${table[*]}" 'BEGIN{n=split(t,a," "); for(i=1;i<=n;i++) print a[i]}'

a
b
c
d
e

you can do the array element access in bash directly as well.

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

1 Comment

Won't preserve embedded spaces in array elements.

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.