0

I've been trying to check and move a file based on whether the file has a timestamp at the end or not. Here's what I have tried. What am I doing wrong?

while read product; do
        if [ -f ${PRODUCT_HOME}/file.*.zip]; then
                echo "Has timestamp."
                mv ${PRODUCT_HOME}/file.*.zip /home/has_time_stamp/file.zip
        else
                echo "No timestamp"
                mv ${PRODUCT_HOME}/file.zip /home/no_time_stamp/file.zip
        fi
done <product_details.txt

Error:

test.sh: 56: [: missing ]

Vimbuddy
  • 166
  • 3
  • 19
  • 1
    `[ -f ${PRODUCT_HOME}/file.*.zip];` should be `[ -f ${PRODUCT_HOME}/file.*.zip ];`, note the extra space. EDIT: but that doesn't seem right either, what if it matches more than one files? – user000001 Mar 21 '18 at 13:34
  • 1
    Canonical question: [Why should there be a space after '\[' and before '\]' in Bash?](https://stackoverflow.com/questions/9581064/why-should-there-be-a-space-after-and-before-in-bash) - Also, https://www.shellcheck.net tells you about problems like this one. – Benjamin W. Mar 21 '18 at 13:34
  • It worked. Thanks. – Vimbuddy Mar 21 '18 at 13:35

0 Answers0