Help with BASH to SH substring

I'm working on porting one of the applications on the 'wiki wanted list' and I'm just missing why this isn't working. After translating all the linux inotify to kqueue you'd think this would be a snap, but I'm really rusty on sh scripting!

The following code works if I use /usr/local/bin/bash as the first line, but changing it to /bin/sh does not.

Code:
#!/bin/sh
#
#  Check if dependencies are installed before build.
#
#  Note:
#  exiftool and ufraw-batch are not needed to build fotoxx,
#  but they are required at run time to handle EXIF data
#  and RAW files from digital cameras.

dlist=" g++ /usr/local/include/gtk-2.0/gtk/gtk.h
        /usr/local/include/tiffio.h  /usr/local/lib/libtiff.so
        /usr/local/bin/xdg-open  /usr/local/bin/xdg-desktop-menu  /usr/local/bin/exiftool"

error=0

for dname in $dlist
do
   if [ ${dname:0:1} = "/" ]
      then find $dname >/dev/null 2>&1
      else which $dname >/dev/null
   fi
   if [ $? -ne 0 ]; then error=1; fi
done

if [ $error -eq 0 ]
   then echo "all dependencies found"
   exit 0
fi

echo ""
echo "The following programs and libraries are required"
echo "(package names depend on your flavor of Linux)."
echo ""
echo "g++                  the Gnu C++ compiler and linker"
echo "libgtk2.0-dev        GTK graphics library (GUI base)"
echo "libtiff4-dev         TIFF file support library"
echo "xdg-utils            LSB standard Linux utilities"
echo "exiftool             EXIF/IPTC image data read and write"
echo ""

for dname in $dlist
do
   if [ ${dname:0} = "/" ]
      then find $dname >/dev/null 2>&1
      else which $dname >/dev/null
   fi
   if [ $? -ne 0 ]
      then echo " missing:  $dname"
      else echo "   found:  $dname"
   fi
done

The error is

Code:
./dependencies.sh: ${dname:1...}: Bad substitution
 
sh(1) doesn't support substrings natively, but I think you can get the same behaviour in your particular script with this:

Code:
#!/bin/sh
#
#  Check if dependencies are installed before build.
#
#  Note:
#  exiftool and ufraw-batch are not needed to build fotoxx,
#  but they are required at run time to handle EXIF data
#  and RAW files from digital cameras.

dlist=" g++ /usr/local/include/gtk-2.0/gtk/gtk.h
        /usr/local/include/tiffio.h  /usr/local/lib/libtiff.so
        /usr/local/bin/xdg-open  /usr/local/bin/xdg-desktop-menu  /usr/local/bin/exiftool"

error=0

for dname in $dlist
do
   if [ ${dname#/*} != ${dname} ]
      then find $dname >/dev/null 2>&1
      else which $dname >/dev/null
   fi
   if [ $? -ne 0 ]; then error=1; fi
done

if [ $error -eq 0 ]
   then echo "all dependencies found"
   exit 0
fi

echo ""
echo "The following programs and libraries are required"
echo "(package names depend on your flavor of Linux)."
echo ""
echo "g++                  the Gnu C++ compiler and linker"
echo "libgtk2.0-dev        GTK graphics library (GUI base)"
echo "libtiff4-dev         TIFF file support library"
echo "xdg-utils            LSB standard Linux utilities"
echo "exiftool             EXIF/IPTC image data read and write"
echo ""

for dname in $dlist
do
   if [ ${dname} = "/" ]
      then find $dname >/dev/null 2>&1
      else which $dname >/dev/null
   fi
   if [ $? -ne 0 ]
      then echo " missing:  $dname"
      else echo "   found:  $dname"
   fi
done

I honestly don't know what the point is of the second for loop.
 
Thank you!

That did fix it.

Honestly, I'm missing the point of the entire script since it checking for dependencies after it builds the program and the program would not build without any of these.

But, since I'm porting it I'd figure I'll first get everything to work the why the author has it working on Linux, then throw out uneeded things. I think the port file should take care of this script.
 
Back
Top