Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

KSH - Problem with braces in variables

Posted on 2011-02-24
4
Medium Priority
?
394 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Suggested Courses

636 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