Solved

Shell Scripting: Get string inside quotations

Posted on 2013-11-08
3
196 Views
Last Modified: 2013-11-08
x=1; \
y=2; \
echo x: $x - '{"y": "$y"}'

Open in new window

I would expect this result:
x: 1 - {"y": "2"}

Open in new window

but instead I get this results:
x: 1 - {"y": "$y"}

Open in new window

0
Comment
Question by:hankknight
  • 3
3 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 39633450
It's because the double quotes are nested within single quotes.  try:
    echo x: $x - '{"y": '"$y"'}'
(that's a single quote between the space and the double quote before the $y, and one between the double-quote after $y and the curly brace)
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39633465
As you can see quotes are hard!

I meant:
    echo x: $x - '{"y": "'$y'"}'
where the extra quotes are between the double-quote and the $y, and between the $y and its trailing double-quote
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39633469
Essentially, you put single quotes round text that you don't want changed at all, then double quotes (or no quotes at all) round bits where you want variable substitution to take place.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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 …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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…

820 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