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. Jerry
On Friday 28 September 2018 14:39:29 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" >Hi Jerry, The problem is that bu the time you're in your script it's already too late. myscript "$plusmore" basically says take the contents of the environment plusmore and pass that to the script. if you call myscript '$plusmore' you will get what you want.
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
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
On Fri, Sep 28, 2018 at 09:39:29AM -0400, Jerry Geis wrote:> I am calling a bash script and passing in somestring that includes a "$" > > myscript "$plusmore"myscript '$plusmore' should work. note the single quotes. If you can't use single quotes, I don't know how to use it,, but there is probably something more arcane that would work, were one a guru. Have you read thru 'man bash', carefully, looking for informatiion on quoting? there is also a document named Advanced Bash Scripting that gives lots of gory details about doing odd things in Bash that might be helpful. Google is your friend. Fred -- ---- Fred Smith -- fredex at fcshome.stoneham.ma.us ---------------------------- Do you not know? Have you not heard? The LORD is the everlasting God, the Creator of the ends of the earth. He will not grow tired or weary, and his understanding no one can fathom. ----------------------------- Isaiah 40:28 (niv) -----------------------------