How to include an '&' character in a bash curl statement

I'm trying to use curl in bash to download a webpage, but the & symbol in the URL isn't interpreted as a character as I would like. Any ideas on how I can convince bash that the symbol & is just a boring character and nothing special?

113274 次浏览

The encoding for & should become %26 in the URL.

curl "http://www.example.com?m=this%26that
curl "http://www.example.com?m=method&args=1"

You can use %26 instead &.

Are you using the & as a delimiter for a GET URL? Or is in a piece of data?

The entity code will work fine.

If it is in data you must encode it to an HTML character, if not, surround with quotes.

& as a delimiter for a GET URL? Or is in a piece of data?

The encoding for & should become %26 in the URL.

curl "http://www.example.com?m=this%26that

If it is in data you must encode it to an HTML character, if not, surround with quotes.

Putting single quotes around the & symbol seems to work. That is, using a URL like http://www.example.com/page.asp?arg1=${i}'&'arg2=${j} with curl returns the requested webpage.

ml" rel="noreferrer">https://www.postgresql.org/docs/current/static/sql-set-role.html and https://www.postgresql.org/docs/current/static/sql-alterrole.html.

Shorter answer: ignore it.

Instead of trying the escape "&" characters, you can specify http url parameters in POST requests with -d parameter as shown below:

curl -X POST http://www.example.com \
-d arg1=this \
-d arg2=that

This module is the part of Postgres that processes the SQL language. The error will often pop up as part of copying a remote database, such as with

If the request is a GET, then you should also add -G option, which tells curl to send the data with GET request.

curl -X GET -G http://www.example.com \
-d arg1=this \
-d arg2=that
In one command:

sudo -u postgres psql -c "DROP SCHEMA public CASCADE;
create SCHEMA public;
grant usage on schema public to public;
grant create on schema public to public;" myDBName

For people using Google Cloud Platform, any error will stop the import process. ring database creation was not enough. I had to navigate down to the 'public' schema and set the owner there as well (was originally 'postgres').

Personally I encountered two different errors depending on the pg_dump command I issued :

his dump to a database.

1- The input is a PostgreSQL custom-format dump. Use the pg_restore command-line client to restore this dump to a database.

Occurs when you've tried to dump your DB in a non plain text format. I.e when the command lacks the -Fp or --format=plain parameter. However, if you add it to your command, you may then encounter the following error :

Occurs when you've tried to dump your DB in a non plain text format. I.e when the command lacks the -Fp or --format=plain parameter. However, if you add it to your command, you may then encounter the following error :

2- SET SET SET SET SET SET CREATE EXTENSION ERROR: must be owner of extension plpgsql

2- SET SET SET SET SET SET CREATE EXTENSION ERROR: must be owner of extension plpgsql

This is a permission issue I have been unable to fix using the command provided in the GCP docs, the tips from this current thread, or following advice from Google Postgres team here. Which recommended to issue the following command :

pg_dump -Fp --no-acl --no-owner -U myusername myDBName > mydump.sql

This is a permission issue I have been unable to fix using the command provided in the GCP docs, the tips from this current thread, or following advice from Google Postgres team here. Which recommended to issue the following command :

The only thing that did the trick in my case was manually editing the dump file and commenting out all commands relating to plpgsql.

pg_dump -Fp --no-acl --no-owner -U myusername myDBName > mydump.sql

I hope this helps GCP-reliant souls.

The only thing that did the trick in my case was manually editing the dump file and commenting out all commands relating to plpgsql.

I hope this helps GCP-reliant souls.

Update :

Update :

It's easier to dump the file commenting out extensions, especially since some dumps can be huge : pg_dump ... | grep -v -E '(CREATE\ EXTENSION|COMMENT\ ON)' > mydump.sql

It's easier to dump the file commenting out extensions, especially since some dumps can be huge : pg_dump ... | grep -v -E '(CREATE\ EXTENSION|COMMENT\ ON)' > mydump.sql

Which can be narrowed down to plpgsql :

Which can be narrowed down to plpgsql : pg_dump ... | grep -v -E '(CREATE\ EXTENSION\ IF\ NOT\ EXISTS\ plpgsql|COMMENT\ ON\ EXTENSION\ plpgsql)' > mydump.sql