Unix Shell - shell script not working

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > shell script not working





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author shell script not working
Gary Wessle

2007-02-19, 7:15 pm

Hi

I have this script which is not mine but I did some modifications and
not it is not producing the second file.
please take a look.

thanks

#!/bin/sh
while echo "Enter filename, or q to quit" ; read fn
do
if [ q = "${fn}" ] ; then exit 1 ; fi
basefn=${fn##*/}
ucbasefn=$(echo "$basefn" | tr '[a-z]' '[A-Z]')_H
if [ -e "${fn}.h" ]
then
echo "${fn}.h already exists"
elif [ -e "${fn}.cpp" ]
then
echo "${fn}.cpp already exists"
else
{
echo "#ifndef ${ucbasefn}"
echo "#define ${ucbasefn}"
echo
echo
echo "class ${basefn}"
echo "{"
echo
echo "public:"
echo
echo "};"
echo
echo "#endif // ${ucbasefn}"
} > "${fn}.h"
echo "#include \"${basefn}.h\""
echo
echo
echo "${basefn}\:\:${basefn}():"
echo "{"
echo
echo "}"
> ${fn}.cpp

break
fi
done
Barry Margolin

2007-02-19, 7:15 pm

In article <m3d545rkce.fsf@localhost.localdomain>,
Gary Wessle <phddas@yahoo.com> wrote:

> Hi
>
> I have this script which is not mine but I did some modifications and
> not it is not producing the second file.


You don't have { } braces surrounding all the lines of the second bunch
of echo commands.

BTW, instead of a series of echo statements, I recommend using a
here-document, i.e.

cat <<EOF > $fn.h
#ifndef $ucbasefn
#define $ucbasefn
....
EOF

> please take a look.
>
> thanks
>
> #!/bin/sh
> while echo "Enter filename, or q to quit" ; read fn
> do
> if [ q = "${fn}" ] ; then exit 1 ; fi
> basefn=${fn##*/}
> ucbasefn=$(echo "$basefn" | tr '[a-z]' '[A-Z]')_H
> if [ -e "${fn}.h" ]
> then
> echo "${fn}.h already exists"
> elif [ -e "${fn}.cpp" ]
> then
> echo "${fn}.cpp already exists"
> else
> {
> echo "#ifndef ${ucbasefn}"
> echo "#define ${ucbasefn}"
> echo
> echo
> echo "class ${basefn}"
> echo "{"
> echo
> echo "public:"
> echo
> echo "};"
> echo
> echo "#endif // ${ucbasefn}"
> } > "${fn}.h"
> echo "#include \"${basefn}.h\""
> echo
> echo
> echo "${basefn}\:\:${basefn}():"
> echo "{"
> echo
> echo "}"
> > ${fn}.cpp
> break
> fi
> done


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com