Home > Mobile >  How to get the exact path of files in a folder using bash script?
How to get the exact path of files in a folder using bash script?

Time:07-20

I have a folder wherein there are two images

  1. dog.jpeg
  2. dog2.jpeg

and I need to send their path in the following queryImage.

    #!/bin/bash
    for i in /Users/user/Desktop/Short/*;
    do
        curl --location --request POST 'some_url' \
        --header 'x-api-key: dummy-api-key' \
        --form 'maxResults="25"' \
        --form 'minConfidence="0.1"' \
        **--form 'queryImage=@"$i"'**
    done

When I try to give the path directly in the following way, we are able to retrieve the path and we get the required output.

     #!/bin/bash
     for i in /Users/user/Desktop/Short/*;
     do
         curl --location --request POST 'some_url' \
         --header 'x-api-key: dummy-api-key' \
         --form 'maxResults="25"' \
         --form 'minConfidence="0.1"' \
         **--form 'queryImage=@"/Users/user/Desktop/Short/dog.jpeg"'**
     done

What am I giving wrong in the first one? How can we get the exact path in queryImage?

Please help. I am a newbie and can't share the details as this is for an internal project.

Thank you :)

CodePudding user response:

Single quotes prevent the substitution at $i.

Use double quotes instead:

#!/bin/bash
for i in /Users/user/Desktop/Short/*
do
    curl --location --request POST 'some_url' \
    --header 'x-api-key: dummy-api-key' \
    --form 'maxResults="25"' \
    --form 'minConfidence="0.1"' \
    **--form "queryImage=@'$i'"**
done
  • Related