Bash not executing correctly with '@' character

Viewed 69

I have the following bash script:

#!/bin/bash
set -x
host=$1
conector=$2
configs='connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1'

echo "{ name: $conector,  config: { $configs } }" > payload.json
curl -v $host/connectors -d @payload.json -H "Content-Type: application/json"

And I can execute in this way:

 bash create.sh http://10.0.0.78:8083 test

If I execute locally in my machine I got the following result:

$ bash create.sh http://10.0.0.78:8083 test
+ host=http://10.0.0.78:8083
+ conector=test
+ configs='connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1'
+ echo '{ name: test,  config: { connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1 } }'
+ curl -v http://10.0.0.78:8083/connectors -d @payload.json -H 'Content-Type: application/json'
*   Trying 10.0.0.78:8083...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:08 --:--:--     0

This ok for me, the server doesn't respond but the "curl -v ... " is correct. Now I tried to execute in Linux Server the same command, and got the following:

+ host=http://10.8.0.78:8083
+ conector=test
+ configs='connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1'
+ echo '{ name: test,  config: { connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1 } }'
+ curl -v http://10.8.0.78:***@payload.json -H 'Content-Type: application/json'
*   Trying 10.8.0.78...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

Note the curl created by the bash in server:

curl -v http://10.8.0.78:***@payload.json

Don't make sense, this URL doesn't exist. I noted this occurs because of '@' character, bash in server is interpreting this character, I don't know why.

Edit 1

Return from command: LC_ALL=C cat -v create.sh

#!/bin/bash
set -x
host=$1
conector=$2
configs='connector.class: io.confluent.connect.jdbc.JdbcSinkConnector, tasks.max: 1'

echo "{ name: $conector,  config: { $configs } }" > payload.json
curl -v $host/connectors -d @payload.json -H "Content-Type: application/json"

Edit 2 I'm using azuredevops to execute script:

jobs:
  - job: Deploy
    pool: ${{parameters.agent}}
    displayName: Deploy
    steps:
      - checkout: templates
      - script: "bash create.sh $(KAFKACONNECT_URL) ${{parameters.conector}} \"${{parameters.configs}}\""

I don't know if this can be the reason for the problem.

Problem Solved

In fact, the "http://10.8.0.78:***@payload.json" is not a problem, the script is executing very well and the URL is correct, but for some reason, AzureDevops Output Console is hidding it instead of show complete URL (as I expected). I enabled "--trace" in curl and saw that curl is posting my payload and URL as I expected. So, the solution is just to accept it, AzureDevops Console is confusing.

1 Answers

for some reason, AzureDevops Output Console is hidding it instead of show complete URL

The Azure console incorrectly believes that http://10.0.0.78:8083/connectors -d @payload.json is a URL of the form http://user:password@host.domain and therefore is replacing what it thinks is a password (8083/connectors -d ) with ***.

Related