2. Bash script runs from Terminal but not from launchd

30 Views Asked by At

The script sorts the download folder into folders with date.

#!/bin/bash
eDate=$(date +%s)                                       #Epochal date
cDate=$(date +%Y-%m-%d)                                     #Current date
fDir=$HOME/Downloads/Browsers/

for x in ${fDir}*;do
    if [[ $(basename "$x") =~ ^[0-9-]+$ ]]; then :
    elif [ $[$eDate - $(date -r "$x" "+%s")] -gt 172800 ];then
        mkdir -p "$fDir$cDate" && mv "$x" "$fDir$cDate"
    fi
done

In terminal it works. launchd returns the error: line 8: 1707452835 - : syntax error: operand expected (error token is " ")

If the folder "$HOME/Downloads/Browsers/" is empty, terminal returns the same error. (Usually this folder is never empty) I can't find the culprit.

0

There are 0 best solutions below