Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escaping the asterisk is failing 1

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
I know that this should be straight forward but for some reason it is not.

I have a variable where I am attempting to store my SQL string but for some reason the command line is doing odd things when I attempt to escape the asterick.

The assignment is as follows:

FILE=$(echo "unload to 'audit"$VAR".unl' select * from pei_audit_trail where change_date < today;")

If I attempt to use the esacpe character the result will give me /* and not *.

If I single quote the asterisk the result will be '*'.

Thanks in advance for your assistance.


SteveR
 
why the echo?

[tt]FILE="unload to 'audit${VAR}.unl' select * from pei_audit_trail where change_date < today;"[/tt]



HTH,

p5wizard
 
p5wizard,

The echo is not necessary it was merely what was in the code I was working with.

However the end result of the assignment is the same. The asterisk is still being expanded on the command line and giving files in the current directory instead of the literal value that I expect.

Thanks for your feedback.

SteveR
 
Hi SteveR77,

Try this:


FILE=$(echo "unload to 'audit"$VAR".unl' select \* from pei_audit_trail where change_date < today;")

Notice the \ before the *.

Good Luck
DrD
 
DrD,

Thank you for your feedback and I apologize. I had the wrong slash in my previous post. The escaping of the asterisk by \* fails and I end up with \* instead of the expected * on its own.

Thank you once again. I'm going to review what I can find on issues with the nested quotes and the command line.

Cheers,

SteveR
 
well, the double quotes do escape the *, so

[tt]var="text with * in it"[/tt]

does just what you'd expect

however, it depends on how you then use that variable

with
[tt]echo $var[/tt]
you will expand the * to a list of all files in current dir

with
[tt]echo "$var"[/tt]
you will not



HTH,

p5wizard
 
p5wizard,

Thank you. That is what I was forgetting. I needed to protect the variable.

SteveR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top