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
Post a Comment