Script writing problem

Self professed idot looking for help
LOL

Hi all, I am new to Unix and I have to write a shell script that will check to see if a file exist and then create it if it does not. The file I need to search for is titled "A1. dat" and here is my feeble attempt at creating the script:

#!/bin/bash

A1=�A1.dat�
for Al in .dat
do
if [ -f $Al]
then
echo �file $Al does exist�
else
echo � file $Al does not exist�
echo �creating file $Al�
touch $Al
fi
done

you are doing stuffs on a single file. hence you dont need for loop.

second, remember to put space on the both side of "[" and "]".

A1=�A1.dat�
do
if [ -f "$Al" ]
then
echo �file $Al does exist�
else
echo �file $Al does not exist�
echo �creating file $Al�
touch $Al
fi

if you also want to check for file size greater than zero, you can use -s flag instead -f.

Thank you sooooooo very much! :slight_smile: