I do got answers on this topic but it is not working still so please help.
Fallowing piece of code in which i m not able to access string array with index as variable i. I m trying to insert a value at respective index but it is not working.
i=0
declare -a str_arr
while read line
do
post=`echo $line| cut -d '|' -f2`
dept=`echo $line| cut -d '|' -f4`
str_arr[$i]="$dept|$post"
i=$(( i+1 ))
done< emp_info.dat
echo ${str_arr[@]}
I m inserting two variables with pipe operator into string array.
output is giving like this
> example.sh: 2: example.sh: declare: not found example.sh: 10:
> example.sh: str_arr[0]=aaaa|developer: not found example.sh: 10:
> example.sh: str_arr[1]=bbbb|tester: not found example.sh: 10:
> example.sh: str_arr[2]=Empower|Senior dev: not found example.sh: 10: