if statement help

Hello.

I am relatively new unix/linux and am writing a script with many sub scripts. One of my choices in the script asks the user to specify a file to be edited. For this I am using the vi command. I want the user to type in a filename to be edited. However, if the user just hits enter I want vi to start as if a new file was being written.

Here is the is my if statement:

echo -n "Enter file name:"
read fname
if fname=NULL
  then
  vi
else
 vi "$fname"
fi

Any help would greatly be appreciated.

From the man page of test:

       -n STRING
              the length of STRING is nonzero

       STRING equivalent to -n STRING

       -z STRING
              the length of STRING is zero

So your if clause could be written as:

if [ -n "$fname" ]
if [ "$fname" ]
if [ ! -z "$fname" ]

Thanks for your help. I was able to get the if clause to do what I wanted.