Question: I need to open multiple files at one go on my linux shell and hence thought of passing the sequence value as the fd value as below:

in my pwd i have files named as nile.300, nile.301,....nile.500

So I want to open nile.300 using fd 300, nile.301 as fd 301 and so on

```
#!/bin/bash
for i in {300..500};do FILENAME=nile.$i
    # Opening file descriptors # 3 for reading and writing
    # i.e. /tmp/out.txt
    exec $i<>$FILENAME

    # Write to file
    echo "Today is $(date)" >&$i
done

sleep 10; 
for i in {300..500};do
    # close fd # 3
    exec $i>&-
done

```

However the script fails to run with ./fd.sh: line 5: exec: 300: not found

Answer: 
Unless you are planning to work on all the open files at the same time, you might be better of processing one file at a time.

This approach eliminate the need to have hundreds of open files at the same time, potentially running into the open file limit.

```
for i in {300..500};do
    FILENAME=nile.$i

    exec 3<>$FILENAME

    # Write to file
    echo "Today is $(date)" >&3
    # Close
    exec 3>&-
done

```
The correct syntax is `{variable}` if it's on the left-hand side:

```
exec {i}<>"$FILENAME"

echo "Today is $(date)" >&$i

exec {i}>&-

```