1

I'm trying to print some record but I'm not able to aimed output

#!/bin/bash

a='xyx_n'
b='xzx_n'
c='xkx_n'

val=(1,2,4,5)
#a=($val)
for (( i=0;i<=3;i++ ))
do
         echo "$a|$b|$c|${val[$i]}" >> "/tmp/test1"
done

Output

xyx_n|xzx_n|xkx_n|1,2,4,5
xyx_n|xzx_n|xkx_n|
xyx_n|xzx_n|xkx_n|
xyx_n|xzx_n|xkx_n|

The output should be like below

xyx_n|xzx_n|xkx_n|1
xyx_n|xzx_n|xkx_n|2
xyx_n|xzx_n|xkx_n|4
xyx_n|xzx_n|xkx_n|5
1
  • 1
    Array assignment should be: val=(1 2 4 5) (no commas) Commented Jun 27, 2015 at 13:00

1 Answer 1

2

Problem with your array initialization -

#!/bin/bash

a='xyx_n'
b='xzx_n'
c='xkx_n'

val=(1 2 4 5)
#a=($val)
for (( i=0;i<=3;i++ ))
do
         echo "$a|$b|$c|${val[$i]}" >> "/tmp/test1"
done

Output

xyx_n|xzx_n|xkx_n|1
xyx_n|xzx_n|xkx_n|2
xyx_n|xzx_n|xkx_n|4
xyx_n|xzx_n|xkx_n|5
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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