To be able to deal with filenames with spaces, here is a better older_than function
# noisily signal success if $1 is older than _any_ of the remaining args
older_than() {
local target="$1"
shift
if [ ! -e "$target" ]
then
echo "updating $target" >&2
return 0 # success
fi
local f
for f in $@
do
if [ "$f" -nt "$target" ]
then
echo "updating $target" >&2
return 0 # success
fi
done
return 1 # failure
}
To be able to deal with filenames with spaces, here is a better older_than function
```
# noisily signal success if $1 is older than _any_ of the remaining args
older_than() {
local target="$1"
shift
if [ ! -e "$target" ]
then
echo "updating $target" >&2
return 0 # success
fi
local f
for f in $@
do
if [ "$f" -nt "$target" ]
then
echo "updating $target" >&2
return 0 # success
fi
done
return 1 # failure
}
```
Thanks!
I think I see one further issue in your version:
```diff
< for f in $@
> for f in "$@"
```
Does this seem right? Reading http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html, it looks like `"$@"` isn't just a bash-ism.
Yes that's the proper way to do it as you can test for yourself. "$@" is special..
#! /bin/sh
a()
{
echo "::a::"
for i in $*
do
echo "$i"
done
}
b()
{
echo "::b::"
for i in $@
do
echo "$i"
done
}
c()
{
echo "::c::"
for i in "$@"
do
echo "$i"
done
}
a "1 2" "3"
b "1 2" "3"
c "1 2" "3"
Yes that's the proper way to do it as you can test for yourself. "$@" is special..
```
#! /bin/sh
a()
{
echo "::a::"
for i in $*
do
echo "$i"
done
}
b()
{
echo "::b::"
for i in $@
do
echo "$i"
done
}
c()
{
echo "::c::"
for i in "$@"
do
echo "$i"
done
}
a "1 2" "3"
b "1 2" "3"
c "1 2" "3"
```
To be able to deal with filenames with spaces, here is a better older_than function
Thanks!
I think I see one further issue in your version:
Does this seem right? Reading http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html, it looks like
"$@"
isn't just a bash-ism.Yes that's the proper way to do it as you can test for yourself. "$@" is special..
My question was about whether it works on platforms I don't have access to. Thanks! I'll send out a fix.
Yes that's bourne shell compatible everywhere.
Committed as
6241e9a4e5
. Many thanks!