foo.sh
doesn't call the function; it just defines it. You need to first source the file, then treat bar
like any other function.
. foo.sh
if bar; then
echo success
else
echo fail
fi
Pregunta
foo.sh :
bar() {
return 1;
}
test.sh
#!/bin/bash
if /path/to/foo.sh bar; then
echo "success"
else
echo "fail"
fi
It always returns "success" regardless of the return value of bar(). How can I make this works as intended?
Solución
foo.sh
doesn't call the function; it just defines it. You need to first source the file, then treat bar
like any other function.
. foo.sh
if bar; then
echo success
else
echo fail
fi