dimanche 25 janvier 2015

Placing a conditional return inside a bash function

I know that its possible to have a return within an if [ ] statement. However, the return (I think) must be an integer, and I need to return a string. For example:



#Function returns a date value formatted %Y-%m-%d
function chartStartsAt () {

CHART_START=`jq 'map(.closedDate | values) | min' < output/json/FullIssueList.json`;
CHART_START="${CHART_START//\"}"

#Check if the date is null, if so return todays date -1
if [ -z CHART_START ]
then
echo "date -v-1d +%Y-%m-%d";
else
echo "${CHART_START%T*}";
fi

}

Aucun commentaire:

Enregistrer un commentaire