[CentOS] Simple bash question

Fri Sep 28 18:40:51 UTC 2018
Leroy Tennison <leroy at datavoiceint.com>

Sounds like you're pretty constrained if you can't escape $plusmore so alternatives may not be possible either but, if possible, put the contents represented by $plusmore in a file and {read,redirect the output from} the file in myscript. Another option might be to put the contents represented by $plusmore in an environment variable and access that from myscript.  The only other option I can think of is to try a different scripting language (awk, perl, tcl, python, you-name-it) to try and get around the issue.


Join us
at the 2018 Momentum User Conference!
Register
here
Leroy Tennison
Network Information/Cyber Security Specialist
E: leroy at datavoiceint.com
2220 Bush Dr
McKinney, Texas
75070
www.datavoiceint.com
TThis message has been sent on behalf
of a company that is part of the Harris Operating Group of
Constellation Software Inc. These companies are listed
here
.
If you prefer not to be contacted by Harris
Operating Group
please notify us
.
This message is intended exclusively for the
individual or entity to which it is addressed. This communication
may contain information that is proprietary, privileged or
confidential or otherwise legally exempt from disclosure. If you are
not the named addressee, you are not authorized to read, print,
retain, copy or disseminate this message or any part of it. If you
have received this message in error, please notify the sender
immediately by e-mail and delete all copies of the
message.

________________________________________
From: CentOS <centos-bounces at centos.org> on behalf of Anand Buddhdev <anandb at ripe.net>
Sent: Friday, September 28, 2018 8:51 AM
To: CentOS mailing list; Jerry Geis
Subject: [EXTERNAL] Re: [CentOS] Simple bash question

On 28/09/2018 15:39, Jerry Geis wrote:

> I am calling a bash script and passing in somestring that includes a "$"
>
> myscript   "$plusmore"
>
> I want to assign in the myscript the $1 arg to something like
> MYTEXT="$1"
>
> when I do that I dont get what I'm expecting. if I do
> MYTEXT='$1'
> I still dont get what I'm expecting.
>
> On the first assignment of MYTEXT I do not want the "$" to be treated as a
> shell variable. I cannot find out how to do that.
>
> I do not have the option of escaping the call to myscipt "\$plusmore". I
> cannot do that.
>
> What am I missing.

You MUST escape the $ in plusmore. If you don't, the calling shell will
try to expand it, and replace it with whatever is in that variable. If
it's not defined, you'll get an empty string. All this happens *before*
myscript is even called.

I'll add that escaping the $ can be done in other ways. Instead of a
backslash, you can also do:

myscript '$plusmore'

Single quotes prevent variable expansion. However, if you are simply
unable to quote $plusmore in some way, then you're stuck.

Anand
_______________________________________________
CentOS mailing list
CentOS at centos.org
https://lists.centos.org/mailman/listinfo/centos