?
Solved

KSH - Problem with braces in variables

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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

765 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