I assume you're actually typing
./myBashScript.sh < text.txt
with a forward slash.
When you run ./myBashScript.sh < text.txt, your interactive shell actually captures the < text.txt and interprets it as a special instruction – in particular, it interprets your command line to mean that it should run myBashScript.sh with standard input connected to text.txt. Your shell then removes < text.txt from the command line before passing off control to myBashScript.sh. So as far as your shell script is concerned, it receives zero arguments, and $2 is empty. Your script translates simply to
echo
which prints a newline.
If you want to actually print the name of the file, you should consider
#!/bin/sh
echo $1
which you can then run:
$ ./myShellScript text.txt
text.txt
If, on the other hand, you want to print the contents of the file, you should use cat(1); your shell script should be
#!/bin/sh
cat $1
which you can then run:
$ ./myShellScript text.txt
Hello from text.txt, a file containing a bunch of test strings.
./myBashScript.sh, is that a typo ? – warl0ck Sep 14 '12 at 13:29