logo
Tags down

shadow

How to reuse a variable in shell script when used in curl?


By : Bill Sullivan
Date : October 17 2020, 08:10 AM
wish helps you When you are using a shell that supports arrays, you can avoid the need for a temporary configuration file.
code :
curl_opts=(-s -o /dev/null -w "%{http_code}")
if /* some condition */
  curl_opts+=(-H "Authorization: Bearer $JWT")
else
  curl_opts+=(--cert "$ADMIN_CERT_PATH" --key "$ADMIN_KEY_PATH")
fi

...

response_code="$(curl "${curl_opts[@]}" "$status_url")"


Share : facebook icon twitter icon

Shell script: output text after cURL variable


By : yka
Date : March 29 2020, 07:55 AM
like below fixes the issue I am trying to do something simple but it's not working. I am trying to echo a stock price from a variable and follow it with text. The problem is that the text does not follow the variable and goes in front of it. , The variable $stock has \r\n at its end.
code :
$ echo $stock | hexdump -c 
0000000   1   0   2   .   9   9  \r  \n                                
0000008
stock=$(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=l1'| tr -d '\r\n')

$ echo ".. $stock .."
.. 102.99 ..

Shell Script CURL JSON value to variable


By : user3582748
Date : March 29 2020, 07:55 AM
it should still fix some issue You could use perl module on command line:
1st, ensure they is installed, under debian based, you could
code :
sudo apt-get install libjson-xs-perl
cpan App::cpanminus
cpan JSON::XS
curlopts=(-X POST -H
    "Content: apent-type: application/x-www-form-urlencoded"
    -d username="$USERNAME" -d password="$PASSWORD")
curlurl=https://www.toontownrewritten.com/api/login?format=json

. <(
    perl -MJSON::XS -e '
        $/=undef;my $a=JSON::XS::decode_json <> ;
        printf "declare -A Json=\047(%s)\047\n", join " ",map {
            "[".$_."]=\"".$a->{$_}."\""
        } qw|queueToken success eta position|;
    ' < <(
        curl "${curlopts[@]}" $curlurl
    )
)
echo ${Json[queueToken]}
6bee9e85-343f-41c7-a4d3-156f901da615

echo ${Json[eta]}
0

How to assign string value to variable from curl and jq in shell script?


By : Vinton Jing
Date : March 29 2020, 07:55 AM
it helps some times I am trying to assign a string I get from curl and jq to a variable. this is my code below, but it doesn't work. I am a Mac user.
code :
$ value=$(curl -X GET https://apitest.onkore.com/onkore/api/v1/storeCategories | 
  jq '.[2] | ._id')
$ echo "$value"
"59178d2a4ca53714085a0903"

Assign a variable in curl URL shell script


By : Music_lovers4
Date : March 29 2020, 07:55 AM
help you fix your problem I believe the problem is in the first headr -H flag. It has white space in the string which might be getting interpreted as another argument to curl.
Here I made some generic modification to the script. I don't have an environment to test it. Hope it helps.
code :
$ cat test.sh
#!/bin/bash

h1flag="'X-Application-Authorization: Bearer Token'"
h2flag="'Accept: application/vnd.application.v2.1+xml'"
reqflag="DELETE"
baseurl="https://api.application.com/hardwares"
while read -r id
do
    curl --verbose -H "${h1flag}" -H "${h2flag}" -X "${reqflag}" "${baseurl}/$id" 
done < input.csv
$ curl --verbose \
  -H 'X-Application-Authorization: Bearer Token' \
  -H 'Accept: application/vnd.application.v2.1+xml' \
  -X DELETE https://api.application.com/hardwares/1945603

use curl in shell script to substitue a variable


By : amr
Date : March 29 2020, 07:55 AM
To fix this issue No variable substitution in single quotes. Switch to double around the expansion, like this:
Related Posts Related Posts :
  • Unix Bash Script - command not found
  • Splitting a large, complex one column file into several columns with awk
  • How to compare two dates of different format?
  • Split string with | character in Bash and export environment variables from first row
  • AWK if else condition not printing correctly
  • Parallel processes in bash, kill with Ctrl C
  • how to move files inside folders in one folder
  • Storing multiple arguments in a string with quotes in shell
  • Bash complete with "@"-sign
  • Problem with comparing numerical values while column-wise parsing CSV file
  • Add to $PATH with Shell Script
  • Check if network drive is mounted, if not send e-mail and try to mount
  • Getting an exit status stored to a variable inside an ssh command
  • Shortcut for opening tmux terminal
  • Can not overwrite folder from source to destination
  • Trickle FTP connection
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org