How expand the variable inside '$1'?

How expand the variable inside '$1'?

Post by Ton » Mon, 23 Jul 2001 16:26:17



I give MyScript the argument 'This text' , i.e.:

   MyScript 'This text'

because I need $1 to expand to 'This text' but I also need the single
quotes included, but when I:

      echo '$1'

in the script I just get:

      '$1'

instead of

      'This text'

Anyone know how to make this work?

Thanks,

-Tony

 
 
 

How expand the variable inside '$1'?

Post by Juergen P. Mei » Mon, 23 Jul 2001 17:27:38



>I give MyScript the argument 'This text' , i.e.:

>   MyScript 'This text'

>because I need $1 to expand to 'This text' but I also need the single
>quotes included, but when I:

>      echo '$1'

>in the script I just get:

>      '$1'

>instead of

>      'This text'

>Anyone know how to make this work?

Use echo "$1" in your script and run your sript this way:

MyScript "'This text'"

Juergen
--


 
 
 

How expand the variable inside '$1'?

Post by Ton » Mon, 23 Jul 2001 18:01:16




>>I give MyScript the argument 'This text' , i.e.:

>>   MyScript 'This text'

>>because I need $1 to expand to 'This text' but I also need the single
>>quotes included, but when I:

>>      echo '$1'

>>in the script I just get:

>>      '$1'

>>instead of

>>      'This text'

>>Anyone know how to make this work?

>Use echo "$1" in your script and run your sript this way:

>MyScript "'This text'"

Thanks....is there a way to get around the double quotes?

-Tony

 
 
 

How expand the variable inside '$1'?

Post by Willia » Tue, 24 Jul 2001 00:25:28



Quote:> I give MyScript the argument 'This text' , i.e.:

>    MyScript 'This text'

> because I need $1 to expand to 'This text' but I also need the single
> quotes included, but when I:

>       echo '$1'

> in the script I just get:

>       '$1'

> instead of

>       'This text'

> Anyone know how to make this work?

Well, the problem is that by the time the string reaches your
script, the single quotes have been stripped off. It's too
late to do anything about it inside your script. However,
if you know you will always need those single quotes, you could
just add them back: echo "'$1'", or whatever works for you.
-Wm
 
 
 

How expand the variable inside '$1'?

Post by Charles Dem » Tue, 24 Jul 2001 02:24:51






>>>I give MyScript the argument 'This text' , i.e.:

>>>   MyScript 'This text'

>>>because I need $1 to expand to 'This text' but I also need the single
>>>quotes included, but when I:

>>>      echo '$1'

>>>in the script I just get:

>>>      '$1'

>>>instead of

>>>      'This text'

>>>Anyone know how to make this work?

>>Use echo "$1" in your script and run your sript this way:

>>MyScript "'This text'"

>Thanks....is there a way to get around the double quotes?

I believe this would work:

MyScript '\'This text\''

I personally don't think this is better, but YMMV.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

How expand the variable inside '$1'?

Post by nos.. » Tue, 24 Jul 2001 02:28:33



> I give MyScript the argument 'This text' , i.e.:

>    MyScript 'This text'

> because I need $1 to expand to 'This text' but I also need the single
> quotes included, but when I:

>       echo '$1'

> in the script I just get:

>       '$1'

> instead of

>       'This text'

Using single quotes like that turns off expansion of $1. Two ways to
get around that are 1) pass the parameter to the script with the
single quotes built in:

MyScript "'This text'"

or 2) add them in when echoing the variable:

echo "'$1'"

 
 
 

How expand the variable inside '$1'?

Post by Geoff Clar » Thu, 26 Jul 2001 03:03:32



Quote:>>>MyScript "'This text'"

>>Thanks....is there a way to get around the double quotes?
>I believe this would work:
>MyScript '\'This text\''

Better make that:

  MyScript \''This text'\'

(Backslash is not special inside single quotes.)

Quote:>I personally don't think this is better, but YMMV.

I agree - it's much easier to `read' the version with the double quotes.

--


 
 
 

1. kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

Hi,

Could you help me debugging a simple csh script:
This script is intended to kill a process by just giving its name, e.g.
KILL this_process

I do it like this:

kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

and actually it tries to kill everything (including my term of course)

The following line works fine:

ps -u`whoami` | grep this_process | awk '{print $1}'

and gives the proper PID

If you have a more elaborated script for that It could be a nice training
example for me.

Thanks for any help.

2. using linux_devel...

3. xfm doesn't expand $1

4. DUAL-PPGA Celeron?

5. Can't get '$1' to work in a .profile alias

6. Update on Pentium II vs Pentium Pro

7. expect script doesn't understand '$1' from command line?

8. New to Linux - need help for networkcard

9. alias RM='mv $1 ~/garbage/'

10. Q: alias psef='ps -ef $1'

11. ps -eo pid,args | awk ' /[b]lah/ { print $1 } ' | xargs kill

12. Formattet output inside variable / line brak inside variable

13. How can I 'echo $$1' so I can actually echo the value stored in the value of $1?