Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Curly brackets converted to unicode in script

Shell Programming and Scripting


Tags
solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-10-2017
Ray-V Ray-V is offline
Registered User
 
Join Date: Jan 2017
Last Activity: 10 January 2017, 4:05 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Curly brackets converted to unicode in script

Is this a bash or wget issue?
GNU bash, version 4.4.0(1)-release (x86_64-slackware-linux-gnu)
GNU Wget 1.18 built on linux-gnu.

If I run wget -O file localhost/{2..4} from the command line, it will download pages 2 to 4 and concatenate them to file - which is what I want.

If I put this in a script, it works.

But if I add variables to the script wget -O file localhost/{$1..$2} and run script 2 4 wget tries to download localhost/%7B2..4%7D

I've worked around this, but it would be better to know why/how the curly brackets are being converted to their unicode equivalents so I can get it to work as required in the first place.
Sponsored Links
    #2  
Old Unix and Linux 01-10-2017
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 24 March 2017, 3:59 PM EDT
Location: Foxborough, MA
Posts: 8,110
Thanks: 217
Thanked 753 Times in 704 Posts
try:

Code:

wget -O file localhost/{${1}..${2}}

Sponsored Links
    #3  
Old Unix and Linux 01-10-2017
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 24 March 2017, 3:50 PM EDT
Location: Aachen, Germany
Posts: 10,521
Thanks: 255
Thanked 3,220 Times in 2,969 Posts
It's a bash feature:

Code:
echo {1..5}
1 2 3 4 5
set -- 1 5
echo {${1}..${2}}
{1..5}

You could use eval, but you should be very aware of its risks!

Code:
eval echo {${1}..${2}}
1 2 3 4 5

The Following User Says Thank You to RudiC For This Useful Post:
Ray-V (01-10-2017)
    #4  
Old Unix and Linux 01-10-2017
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 March 2017, 11:16 AM EDT
Location: Amsterdam
Posts: 11,331
Thanks: 479
Thanked 3,247 Times in 2,864 Posts
Variables cannot be used in brace expansions. This is because of the parsing order. From a man bash:

Quote:
Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.
Sponsored Links
    #5  
Old Unix and Linux 01-10-2017
Ray-V Ray-V is offline
Registered User
 
Join Date: Jan 2017
Last Activity: 10 January 2017, 4:05 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
You could use eval, but you should be very aware of its risks!
Many thanks - eval is what I needed. Had to do the command substitution on the whole URL wget -O file $(eval echo localhost/{$1..$2}), but it now works.

Should have known this because I've used eval before - must have had a mental block, but at least I've been prompted now to understand its use better.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script - entered input(1-40 bytes) needs to be converted exactly 40 bytes shravan.300 Shell Programming and Scripting 3 01-22-2013 01:48 AM
Shell Variable in Curly Brackets Returns Empty Value coolguyamy Shell Programming and Scripting 3 05-02-2012 08:01 AM
Python converted from /bin/sh shell - backup script. jzacsh Programming 0 10-24-2009 08:05 PM
How to display unicode characters / unicode string jackdorso Programming 3 05-20-2005 01:09 PM
how do you use brackets ?? in a script. moxxx68 Shell Programming and Scripting 3 09-27-2004 10:57 PM



All times are GMT -4. The time now is 04:04 PM.