0

When I run the following command in a directory of an extracted (inflated) XLSX, I get the all URLs found within the sub-folder files.

find . -exec exiftool {} \; | grep http

Now I want to run this as part of a bash script I have developed but it simply doesn't show anything upon completion.

Here is the code in the script:

if [[ $fileName == *.xlsx ]]; then 
    #file is XML based, create new directory with file name, copy file there and extract
    echo "Creating directory\n"
    DATE=`date +%Y-%m-%d`
    mkdir "Files/$DATE-$fileName-$USER"
    cp $filePath "Files/$DATE-$fileName-$USER"
    unzip "Files/$DATE-$fileName-$USER/$fileName" -d "Files/$DATE-$fileName-$USER/"
    result="find 'Files/$DATE-$fileName-$USER/$fileName' -exec exiftool {} \; | grep http"
    printf $result
fi

Your support is appreciated in figuring out what's wrong here.

5
  • 1
    is it just me, or are you not executing the find command, at all? Commented Mar 3, 2018 at 8:23
  • also the == *.xlsx ... is this a real construct? wouldn't be better served by something like if echo $filename | grep -E '*[.]xlsx$' ; then Commented Mar 3, 2018 at 8:26
  • @MichaelSpeer There are multiple ways of performing this check , mine and yours are just two of them. Nonetheless, if the result is the same in this use case, it becomes a matter of preference. Commented Mar 3, 2018 at 8:47
  • @MichaelSpeer, that construct has the benefit of working in a POSIX shell, but is unnecessarily heavy in bash. Also, the regular expression in your comment is incorrect, as the * is supposed to represent "zero or more of the preceding atom". Commented Mar 4, 2018 at 14:27
  • @ghoti thank you for the correction. I prefixed my other comment wondering if it was a real construct, as opposed to a misunderstanding. I later looked through the extensive bash man-page and found it. I was simply unfamiliar with it previously, and therefore questioned it alongside the apparently non-functional find statement. Thank you both for educating me in the matter Commented Mar 5, 2018 at 1:29

1 Answer 1

3

You don't call the command, there is the assignment

result="find 'Files/$DATE-$fileName-$USER/$fileName' -exec exiftool {} \; | grep http"

But the command is treated as a string and never executed. Also the variables in single quotes won't expand. Instead, write

result="$(find "Files/$DATE-$fileName-$USER/$fileName" -exec exiftool {} \; | grep http)"

Other improvements

echo does not recognize \n by default. Replace echo "Creating directory\n" with echo "Creating directory" and add another empty echo for an additional newline.

printf $result may swallow % escape sequences and the parts after the first space. Quote the variable and use %s: printf %s "$result".

Don't pass directories and the files inside them to exiftool. Either use exiftool's recursive option and drop the find part or add -type f to the find command, such that only files are listed.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok....So I replaced by bit with yours but I still see no output of the find command...
@ksa_coder Did you assign any value to $fileName, does that value end with .xlsx? Can you confirm that there are any files inside Files/$DATE-$fileName-$USER/$fileName and at least one of them has a meta-data field containing the search string http?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.