Bash array and loop won't work together -


i pretty new in bash script , can't figure out why piece of code doesn't work (yes i've googled around).

here's code:

if [ $usertype = normal ]     commands[0]="hi" ; descriptions[0]="get greeted"     commands[1]="test" ; descriptions[1] = "test" elif [ $usertype = hacker ]     commands[0]="hi" ; descriptions[0]="get greeted"     commands[1]="test" ; descriptions[1] = "test" fi  alias fhelp=' ((i=0; i<=${commands[@]}; i++))     printf '%s %s\n' "${commands[i]}" "${descriptions[i]}" done' 

any ideas?

thanks in advance.

you can't use single quotes inside single quotes. this, treats "'" string of single quote , concatenate them.

alias fhelp=' ((i=0; i<=${commands[@]}; i++))   printf '"'"'%s %s\n'"'"' "${commands[i]}" "${descriptions[i]}" done' 

and use ${#commands[@]} array length.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -