I am pretty new in bash script and can't figure out why this piece of code doesn't work (yes I've googled around).
Here's my code:
if [ $usertype = normal ]
then
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='
for ((i=0; i<=${commands[@]}; i++))
do
printf '%s %s\n' "${commands[i]}" "${descriptions[i]}"
done'
Any ideas?
Thanks in advance.
printf '%s %s\n' "${commands[i]}" "${descriptions[i]}"can be replaced usingecho "${commands[i]} ${descriptions[i]}"-- much cleaner and better.echoinstead ofprintf. Pls see cyberciti.biz/faq/finding-bash-shell-array-length-elements