# while loop error. (command not found)

**URL:** <https://community.unix.com/t/while-loop-error-command-not-found/308707>\
**Category:** Shell Programming and Scripting\
**Created:** [April 19, 2012, 6:40pm UTC](https://community.unix.com/t/while-loop-error-command-not-found/308707 "2012-04-19T18:40:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kashif.live](https://community.unix.com/letter_avatar/kashif.live/32/5_5575768a8748004e209b776fc1b2916d.png) [@kashif.live](https://community.unix.com/u/kashif.live)\
**Post date:** [April 19, 2012, 6:40pm UTC](https://community.unix.com/t/while-loop-error-command-not-found/308707/1 "2012-04-19T18:40:01Z")

</div>

can any1 please tell me what is problem with following code:

```nohighlight
i=1;
cat test| while read CMD;
do
Var$i=$CMD; or Var$i=$(echo $CMD) ;
let i++ 
done

```

I keep getting error :

```nohighlight
line 4: Var1=sometext: command not found

```

---

<div class="post-metadata">

**Author:** ![47shailesh](https://community.unix.com/letter_avatar/47shailesh/32/5_5575768a8748004e209b776fc1b2916d.png) [@47shailesh](https://community.unix.com/u/47shailesh)\
**Post date:** [April 19, 2012, 8:02pm UTC](https://community.unix.com/t/while-loop-error-command-not-found/308707/2 "2012-04-19T20:02:00Z")

</div>

that's a useless use of cat. and for your problem use following

```nohighlight
i=1;
while read CMD
do
eval Var$i=$CMD
let i++ 
done < test

```

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 19, 2012, 8:08pm UTC](https://community.unix.com/t/while-loop-error-command-not-found/308707/3 "2012-04-19T20:08:42Z")

</div>

That's a useless use of eval, and eval is dangerous -- someone could feed text like ``rm -Rf ~/`` into the program, and it would do it.

Just do this instead:

```nohighlight
i=1
while read var$i
do
        let i++
done <inputfile

```
