|
Home > Archive > Unix Shell > May 2007 > shell script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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.
| |
| SiKing 2007-05-17, 7:16 am |
| 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------
| |
| Bill Marcum 2007-05-17, 7:16 am |
| 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.
| |
| Chris F.A. Johnson 2007-05-17, 7:16 am |
| 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
| |
| maaz@cox.net 2007-05-17, 1:18 pm |
| 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
| |
|
| On May 18, 12:50 am, m...@cox.net wrote:
> On May 16, 11:43 pm, Ivan <find.i...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
> Did you try
>
> sed -i "/$1/d" */test1
Hi there..
Yep, using double quotes instead of single worked perfectly..
Cheers for that!
|
|
|
|
|