# bash variable string declaration

**URL:** <https://community.unix.com/t/bash-variable-string-declaration/305239>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [February 23, 2012, 10:44am UTC](https://community.unix.com/t/bash-variable-string-declaration/305239 "2012-02-23T10:44:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![verse123](https://community.unix.com/letter_avatar/verse123/32/6_22734026db12803ebb3e059622ac3534.png) [@verse123](https://community.unix.com/u/verse123)\
**Post date:** [February 23, 2012, 10:44am UTC](https://community.unix.com/t/bash-variable-string-declaration/305239/1 "2012-02-23T10:44:43Z")

</div>

Hello,

Why is this not working in a script?

```plaintext
files="test.fsa"
echo $files
for file in $files
do
        if [! -e "$file"]
                then
                        echo "$file does not exist."
        fi
       run a command
done

```

I get an error saying

> [@](#):
>
> files=contig.fsa: Command not found.  
> files: Undefined variable.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 23, 2012, 10:49am UTC](https://community.unix.com/t/bash-variable-string-declaration/305239/2 "2012-02-23T10:49:17Z")

</div>

Did you edit this script in Microsoft Notepad? That will fill the file with useless carriage returns that will confuse the shell in many ways.

---------- Post updated at 09:49 AM ---------- Previous update was at 09:48 AM ----------

If "test.fsa" is a list of files, you should be doing this:

```nohighlight
while read file
do
...
done < test.fsa

```

---

<div class="post-metadata">

**Author:** ![verse123](https://community.unix.com/letter_avatar/verse123/32/6_22734026db12803ebb3e059622ac3534.png) [@verse123](https://community.unix.com/u/verse123)\
**Post date:** [February 23, 2012, 12:02pm UTC](https://community.unix.com/t/bash-variable-string-declaration/305239/3 "2012-02-23T12:02:01Z")

</div>

No I wrote it with vi editor. I have no idea what's going on. I also tried this (the entire script):

```plaintext
#!/bin/sh
#
#$ -pe threaded 20
#$ -l mem_free=50G
#$ -cwd
for i in *.txt
do
        if [-f $i]
                then
                        echo "$i exists, proceeding with description generator..."
                else
                        echo "there is an error processing $i ... check it."
        fi

./f1 $i ./description-tables/$i-output 10 30 40 DATA
done

```

I received an error message saying:

> [@](#):
>
> for: No match.  
> do: Command not found.  
> i: Undefined variable.

What's going on here?

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 23, 2012, 2:12pm UTC](https://community.unix.com/t/bash-variable-string-declaration/305239/4 "2012-02-23T14:12:54Z")

</div>

cat -v script.sh
