Operating System - HP-UX
1753808 Members
8435 Online
108805 Solutions
New Discussion

How to avoid substitution with string having * characters

 
SOLVED
Go to solution
SwissKnife
Frequent Advisor

How to avoid substitution with string having * characters

Hi,

 

Here is my script

 

function myfunction {
    __TEXT=`echo "$1"`
    echo "__TEXT=${__TEXT}"
}

__AA="*** Erreur dans le passage du nombre d'arguments"
myfunction ${__AA}

 

My question: How to get this as an output from this script:

*** Erreur dans le passage du nombre d'arguments

 

Instead of this, it returns a string containing filenames !!!

 Note: I understand the WHY!!! But I do not know how to do the trick! in other words how to avoid the wildcard expansion ???

 

Any ideas ? thanks in advance.

 

Kind regards,

Den.

3 REPLIES 3
Steven Schweda
Honored Contributor
Solution

Re: How to avoid substitution with string having * characters

> Note: I understand the WHY!!!

   Perhaps.  Perhaps not.

>  But I do not know how to do the trick! in other words how to avoid
> the wildcard expansion ???

   The usual "trick" is quotation.

> myfunction ${__AA}

      myfunction "${__AA}"

   Another method might be "set -f".  As usual, many things are
possible.

Dennis Handly
Acclaimed Contributor

Re: How to avoid substitution with string having * characters

> __TEXT=`echo "$1"`

 

What is the purpose of this?  Why not: __TEXT="$1"

Steven Schweda
Honored Contributor

Re: How to avoid substitution with string having * characters

> > __TEXT=`echo "$1"`
> What is the purpose of this?  Why not: __TEXT="$1"

   Or even: __TEXT=$1

pro3$ x='aa bb cc'
pro3$ y=$x
pro3$ echo $y
aa bb cc

   In more complicated expressions, more quotation may be more helpful.


   For future reference:

> Note: I understand the WHY!!!

   A statement like this conveys no useful information.  What, exactly,
do you know (or believe that you know)?  Are you saying that that you
understand how the shell "globs" a "*"?  Or that you understand how
quotation works?  Or what?

   In many cases, the act of forming a question well will itself lead
you to the answer, which can save everyone some work.