Issue escaping single quotes in bash function
Hi,
I'm writing a bash script containing three functions: f_A, f_B and f_C. 1. f_A invoke f_B by passing it the string argument "Alpha". 2. f_B call f_C by passing it a partly dynamically constructed string. My issue is this: I can't find the right syntax to build the string to pass to f_C. In brief: Quote:
Code:
f_B() { Unfortunately I can't replace single quotes with double ones, the only accepted syntax is the one with single quotes I've tried the following syntaxes with no luck: Quote:
I've never been able to get the desired string. Thanks in advance to anyone who can help me. |
hi and welcome here, at LQ
I would suggest you to user www.shellcheck.net to check your script, it will help you to fix issues like this. Additionally you need to post your script, now we can't see the relevant parts therefore hard to tell you anything You can also use set -xv at the beginning of your script to see what's happening. Finally Code:
FQDN=$(echo "$1") |
What pan64 said, but I think there's a problem if you specifically have a file named like:
Code:
/hosts/host'some-name' Perhaps you can print out some examples of: variable name is <blah> Resultant string needs to be exactly <blah-blah> with all the syntax and punctuation as you feel it's needed to be. |
Thanks for the replies to rtmistler and pan64. I especially appreciate the tip about shellcheck.net. The string of rtmistler's example doesn't represents a filename but is a string to pass out to an XML parser ("xpath" from "perl-XML-XPath" package), so I thought I needed to pass it to the parser with exactly defined quotes. I think I'm close to solving the problem with the help of shellcheck too. Probably "xpath" can accept the syntax
Code:
"/hosts/host[name='Alpha']" Code:
'/hosts/host[name="Alpha"]' Ruso |
Code:
f_B() { But a literal space or quote needs to be quoted. Command arguments normally must have "" quotes around a $var or $( ) The function f_C is like a command so must have "$APIPATH". |
Quote:
Code:
[rkn] Desktop $ FQDN=Alpha Code:
[rkn] Desktop $ set -x |
All times are GMT -5. The time now is 03:47 PM. |