Re: Using a variable in the exho of another variable

I don't know exactly what you want to do. Maybe you can use a for-loop. If the names are files in the current directory, you can get them into the variable 'name' and get an associated counter 'i' like this. (Try it in a directory with rather few files!)

Code:

i=0;for name in *;do i=$((i=$i+1));echo -n "$i: "; echo $name;done

You can find the following description of the for command in

Code:

man bash

Code:

for name [ in word ] ; do list ; done
The list of words following in is expanded, generating a list of
items. The variable name is set to each element of this list in
turn, and list is executed each time. If the in word is omit‐
ted, the for command executes list once for each positional
parameter that is set (see PARAMETERS below). The return status
is the exit status of the last command that executes. If the
expansion of the items following in results in an empty list, no
commands are executed, and the return status is 0.
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres‐
sions is invalid.