I am passing username and password to the curl command to receive the output from the api call. Not sure whats wrong, but the curl command works from the command line, but when I use the same curl command within a bash script, it doesn't take the credentials properly. API call fails with an authorization error. Can someone throw some pointers here?
curl --silent -u 'blah-blah:youareawesome$1234' https://example.com/api/check
Here is the script
USERNAME=$1
PASSWORD=$2
curl --silent -u "${USERNAME}:${PASSWORD}" https://example.com/api/check
{"timestamp":1509422967185,"status":401,"error":"Unauthorized","message":"Bad credentials","path":"/api/check"}
USERNAME != USER? however, PASSWORD=PASSWORD ;-) If that solves your problem, please delete this Q as misspellings in code are off-topic. Good luck.$USERis a reserved variable name (automatically set to the current username). It's best to use lowercase (or mixed-case) variable names to avoid conflicts like this.set -xti the script just before thecurlcommand, so it'll print the equivalent of what it's actually running (note: what it prints isn't literally what's being executed, it's something equivalent to it, but sometimes with strange quoting or escaping of arguments).