|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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------ |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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! |
|
![]() |
| Outils de la discussion | |
|
|