PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > shell script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

shell script

Réponse
 
LinkBack Outils de la discussion
Vieux 17/05/2007, 07h43   #1
Ivan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut shell script

Hi all..

I need to make a script incorporating the following command:
sed -i '/$NAME/d' */test1

I'm having a bit of trouble .. I'd be happy with the script to look
like this:



sed -i '/$1/d' */test1

So that when I type
$ ./script dan

The command sed -i '/dan/d' */test1 would execute, but unfortunately
it does not work this way..

Not when I use
sed -i '/$1/d' */test1
nor when I use
sed -i '/"$1"/d' */test1

Would anyone have any ideas on how I can get this to work?

Thanks,


Ivan.

  Réponse avec citation
Vieux 17/05/2007, 08h13   #2
SiKing
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script

Ivan wrote:
> I need to make a script incorporating the following command:
> sed -i '/$NAME/d' */test1
>
> I'm having a bit of trouble .. I'd be happy with the script to look
> like this:
>
> sed -i '/$1/d' */test1
>
> So that when I type
> $ ./script dan
>
> The command sed -i '/dan/d' */test1 would execute, but unfortunately
> it does not work this way..
>
> Not when I use
> sed -i '/$1/d' */test1
> nor when I use
> sed -i '/"$1"/d' */test1


Everything inside of the single quotes (in your case '/$1/d') will not be seen
by the shell but will passed literally to sed. Try putting eval in front of it,
to unpack the $1 first.

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
------END GEEK CODE BLOCK------
  Réponse avec citation
Vieux 17/05/2007, 08h59   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script

On 16 May 2007 23:43:30 -0700, Ivan
<find.ivan@gmail.com> wrote:
>
>
> Hi all..
>
> I need to make a script incorporating the following command:
> sed -i '/$NAME/d' */test1
>
> I'm having a bit of trouble .. I'd be happy with the script to look
> like this:
>
>
>
> sed -i '/$1/d' */test1
>
> So that when I type
> $ ./script dan
>
> The command sed -i '/dan/d' */test1 would execute, but unfortunately
> it does not work this way..
>

Use double quotes instead of single quotes.



--
No one can put you down without your full cooperation.
  Réponse avec citation
Vieux 17/05/2007, 09h05   #4
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script

On 2007-05-17, Ivan wrote:
> Hi all..
>
> I need to make a script incorporating the following command:
> sed -i '/$NAME/d' */test1
>
> I'm having a bit of trouble .. I'd be happy with the script to look
> like this:
>
> sed -i '/$1/d' */test1
>
> So that when I type
> $ ./script dan
>
> The command sed -i '/dan/d' */test1 would execute, but unfortunately
> it does not work this way..
>
> Not when I use
> sed -i '/$1/d' */test1
> nor when I use
> sed -i '/"$1"/d' */test1
>
> Would anyone have any ideas on how I can get this to work?


Variables are not expanded within single quotes. Use double quotes:

sed -i "/$1/d" */test1

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 17/05/2007, 15h50   #5
maaz@cox.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script

On May 16, 11:43 pm, Ivan <find.i...@gmail.com> wrote:
> Hi all..
>
> I need to make a script incorporating the following command:
> sed -i '/$NAME/d' */test1
>
> I'm having a bit of trouble .. I'd be happy with the script to look
> like this:
>
> sed -i '/$1/d' */test1
>
> So that when I type
> $ ./script dan
>
> The command sed -i '/dan/d' */test1 would execute, but unfortunately
> it does not work this way..
>
> Not when I use
> sed -i '/$1/d' */test1
> nor when I use
> sed -i '/"$1"/d' */test1
>
> Would anyone have any ideas on how I can get this to work?
>
> Thanks,
>
> Ivan.


Did you try

sed -i "/$1/d" */test1

  Réponse avec citation
Vieux 18/05/2007, 00h19   #6
Ivan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script

On May 18, 12:50 am, m...@cox.net wrote:
> On May 16, 11:43 pm, Ivan <find.i...@gmail.com> wrote:
>
>
>
> > Hi all..

>
> > I need to make a script incorporating the following command:
> > sed -i '/$NAME/d' */test1

>
> > I'm having a bit of trouble .. I'd be happy with the script to look
> > like this:

>
> > sed -i '/$1/d' */test1

>
> > So that when I type
> > $ ./script dan

>
> > The command sed -i '/dan/d' */test1 would execute, but unfortunately
> > it does not work this way..

>
> > Not when I use
> > sed -i '/$1/d' */test1
> > nor when I use
> > sed -i '/"$1"/d' */test1

>
> > Would anyone have any ideas on how I can get this to work?

>
> > Thanks,

>
> > Ivan.

>
> Did you try
>
> sed -i "/$1/d" */test1




Hi there..

Yep, using double quotes instead of single worked perfectly..

Cheers for that!

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h41.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13825 seconds with 14 queries