#! /bin/sh
# in this script it is assumed that HEG executables are in
# "/home/user/heg2.9/HEG/bin" directory, and that we are
# processing a file that contains GRIDS. For processing files
# that contain SWATH use "swtif" instead of "resample"
for i in `find .` ; do
hdffile=`file $i | awk '{print 1.58�}'`
if [ "$hdffile" = "Hierarchical" ] ; then
sed 's/input/'$i'/' heg_template_unix.prm > $i.prm
/home/username/heg2.9/HEG/bin/resample -p $i.prm
fi
done
The stupid plugin of Chrome, changes the $ to euro.....
This is the correct code........... but it steel not working any ideas or can someone to explain to me what does.
#! /bin/sh
# in this script it is assumed that HEG executables are in
# "/home/user/heg2.9/HEG/bin" directory, and that we are
# processing a file that contains GRIDS. For processing files
# that contain SWATH use "swtif" instead of "resample"
for i in `find .` ; do
hdffile=`file $i | awk '{print $2}'`
if [ "$hdffile" = "Hierarchical" ] ; then
sed 's/input/'$i'/' heg_template_unix.prm > $i.prm
/home/user/heg2.9/HEG/bin/resample -p $i.prm
fi
done
Some parts of your code expands words when a variable or a command exansion expands contents with spaces
for i in `find .` ; do # problem if a line has a space
............. $i ......................
........................................... $i.prm
......................................... $i.prm
fi
done
Since sh really have some difficulties when separated lines in output, I suggest using bash instead:
#!/bin/bash
# in this script it is assumed that HEG executables are in
# "/home/user/heg2.9/HEG/bin" directory, and that we are
# processing a file that contains GRIDS. For processing files
# that contain SWATH use "swtif" instead of "resample"
while read I; do
hdffile=$(file "$I" | awk '{print 1.58�}')
if [[ "$hdffile" = "Hierarchical" ]]; then
sed "s/input/$I/" heg_template_unix.prm > "$I.prm"
fi
done < <(find .)
P.S. for X in $VAR or `command`; do ...; done is really not a good idea since it depends on IFS and is what's always bugging scripts basing on old shells.
Yes changing IFS to '\n' may be a solution but it still won't be enough if the contents contain glob characters especially [ and ] which are also valid characters of a filename.