Solved

KSH - Problem with braces in variables

Posted on 2011-02-24
4
392 Views
Last Modified: 2012-05-11
Hi,

$ cat test2.ksh 
#!/bin/ksh

MYVAL="1.2.3,4.5.6"

echo \{${MYVAL}\}
X="\{${MYVAL}\}"
echo $X
Y=`echo \{${MYVAL}\}`
echo $Y

Open in new window



$ ./test2.ksh 
{1.2.3,4.5.6}
\1.2.3 \4.5.6\
1.2.3 4.5.6

Open in new window




Why does this happen and how do I fix it ?
0
Comment
Question by:TwentyFourSeven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:sergiobg57
ID: 34974334
I'm not logged on my linux right now to help you out with precision but i'll try to guess here what the string should look like:

X="'{'${MYVAL}'}'"

Open in new window


Btw, why aren't you using bash?
0
 
LVL 1

Author Comment

by:TwentyFourSeven
ID: 34974770
> Btw, why aren't you using bash?

Can't remember.  Why should I be using bash instead ?  ;)
0
 
LVL 1

Author Comment

by:TwentyFourSeven
ID: 34974930
BTW, your answer gives


''1.2.3' '4.5.6''
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 34975630
You don't say what output you want/expect.

Try this:

#!/bin/ksh

MYVAL="1.2.3,4.5.6"

echo "{$MYVAL}"
X="{$MYVAL}"
echo "$X"

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question