[SOLVED] bash changes { to %7B and } to %7D

Forum rules
Before you post please read how to get help
Post Reply
tolga
Level 1
Level 1
Posts: 10
Joined: Fri Mar 10, 2017 5:02 pm

[SOLVED] bash changes { to %7B and } to %7D

Post by tolga » Wed Aug 29, 2018 12:06 pm

Hi Everyone,

I am running into a weird issue for the past days.

I have a simple script that downloads files with wget as follows:

Code: Select all

wget -r -np -nd http://website.com/document{01..20}.pdf
wget -r -np -nd http://somesite.com/document{01..20}.pdf
wget -r -np -nd http://anothersite.com/document{01..20}.pdf
However when I run the script, the terminal output shows (below is one example. The error is the same for each address - website.com, somesite.com, anothersite.com).

Code: Select all

--2018-08-29 18:54:41--  http://website.com/document%7B01..20%7D.pdf
Resolving website.com
Connecting to website.com... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-08-29 18:54:41 ERROR 404: Not Found.
I thought that the script file could be corrupt and I wrote it from scratch in a new file. That did not change anything.

When I copied the lines from the file and ran from the terminal, it executed without any errors:

Code: Select all

wget -r -np -nd http://website.com/document{01..20}.pdf ; wget -r -np -nd http://somesite.com/document{01..20}.pdf ;wget -r -np -nd http://anothersite.com/document{01..20}.pdf
Any ideas on what can be wrong?

Thank you.
Tolga
Last edited by tolga on Sun Sep 02, 2018 11:34 am, edited 1 time in total.

FreedomTruth
Level 4
Level 4
Posts: 418
Joined: Fri Sep 23, 2016 10:19 am

Re: bash changes { to %7B and } to %7D

Post by FreedomTruth » Wed Aug 29, 2018 12:53 pm

Are you positive your script is using bash (not "sh")? #!/bin/bash
It seems to all work correctly on my system, wget directly from terminal or in a script file.

(edit) just tried with dash instead, it came up with the same thing you were experiencing, trying to get a single file named "document{01..20}.pdf"
If you abide in My word, you are My disciples indeed. And you shall know the truth, and the truth shall make you free... Most assuredly, I say to you, whoever commits sin is a slave of sin... Therefore if the Son makes you free, you shall be free indeed.

tolga
Level 1
Level 1
Posts: 10
Joined: Fri Mar 10, 2017 5:02 pm

Re: bash changes { to %7B and } to %7D

Post by tolga » Wed Aug 29, 2018 2:41 pm

Hi @FreedomTruth,

Thank you very much for your reply.

I am positive that I use /bin/bash. And, following your point, I tried with dash and I got the same result.

It seems very weird that the exact same line works when run through the terminal but not from the script.

Frankly I have no idea what is going on and where to start troubleshooting :(

FreedomTruth
Level 4
Level 4
Posts: 418
Joined: Fri Sep 23, 2016 10:19 am

Re: bash changes { to %7B and } to %7D

Post by FreedomTruth » Wed Aug 29, 2018 4:15 pm

Hmm.. how are you calling the script?
./script.sh is not the same as sh ./script.sh

Other than that, I'm also confused why it would behave differently.

Code: Select all

$ cat test.sh
#!/bin/bash
echo {01..10}
$ ./test.sh
01 02 03 04 05 06 07 08 09 10
$ dash ./test.sh
{01..10}
$
If you abide in My word, you are My disciples indeed. And you shall know the truth, and the truth shall make you free... Most assuredly, I say to you, whoever commits sin is a slave of sin... Therefore if the Son makes you free, you shall be free indeed.

gm10
Level 13
Level 13
Posts: 4599
Joined: Thu Jun 21, 2018 5:11 pm

Re: bash changes { to %7B and } to %7D

Post by gm10 » Wed Aug 29, 2018 5:08 pm

tolga wrote:
Wed Aug 29, 2018 2:41 pm
I am positive that I use /bin/bash.
Almost certainly not. Run the script like this bash <script> and you'll most likely see it works. Also post the full script contents please.

User avatar
smurphos
Level 8
Level 8
Posts: 2238
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher...

Re: bash changes { to %7B and } to %7D

Post by smurphos » Thu Aug 30, 2018 1:54 am

Shebang your script. As has been posted this works fine in bash. Neighter sh or dash support brace expansion.

Code: Select all

#!/bin/bash
wget -r -np -nd http://website.com/document{01..20}.pdf
wget -r -np -nd http://somesite.com/document{01..20}.pdf
wget -r -np -nd http://anothersite.com/document{01..20}.pdf

tolga
Level 1
Level 1
Posts: 10
Joined: Fri Mar 10, 2017 5:02 pm

Re: bash changes { to %7B and } to %7D

Post by tolga » Sun Sep 02, 2018 11:34 am

Thank you very much @gm10 and @smurphos. This was really driving me nuts!

I used both of your suggestions and it worked like a charm:
  1. I shebanged my script,
  2. I ran it with bash my_script.sh
Thank you very much for your kind assistance once again!

Post Reply

Return to “Scripts & Bash”