0

I have a method where I'm executing a curl command and it returns the result. I would like to pass arguments to this method but it isn't working.

commande_mine() {
    local MY_OUTPUT=$(curl -X POST \
  http://localhost:5000/myapp \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
        "filepath": "$1"
    }')
    echo $MY_OUTPUT
}

for f in "/Users/anthony/my files"/*
do 
    commande_mine $f >> test.txt
    break # break first time until everything works as expected
done

How can I use the $f parameter passed into the function inside the curl command?

0

1 Answer 1

1

You can use:

commande_mine() {
  local MY_OUTPUT=$(curl -X POST \
  http://localhost:5000/myapp \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
        "filepath": "'"$1"'"
    }')
    echo "$MY_OUTPUT"
}

and call it as:

for f in "/Users/anthony/my files"/*
do 
    commande_mine "$f"
    break
done > test.txt
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.