Solved

Shell Scripting: Get string inside quotations

Posted on 2013-11-08
3
197 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
[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
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to monitor servers ? 4 64
edit firefox cookie settings via shell script on ubuntu 14? 1 72
Windows 10 linux VM 30 92
NFS v4 7 76
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

752 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