Solved

KSH - Problem with braces in variables

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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 …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now