Solved

KSH - Problem with braces in variables

Posted on 2011-02-24
4
390 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…

830 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