Bash question

Discuss Programming
Post Reply
Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Bash question

Post by Master of Reality »

if i wanted to echo the arguments in a command and needed it to change my to your, and myself to yourself, mine to yours, etc, and vice versa. What would i have to do?
i know to echo the arguments a ijust put echo $*.
Should i be reading the bash man page?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Code: Select all

echo $* | sed s/my/your/ig
Is using sed cheating?

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality »

now, why doesnt it work if i put it more then once:

Code: Select all

echo $* | sed /s/my/your/ig | sed /s/my/your/ig

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Get rid of the leading "/", but why do you need the same thing twice? My example acounts for both my->your and myself->yourself.

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality »

d'oh... well i willl have to add mine <-> yours and i will have to put you/me and me/you (i need it to go both ways)

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality »

Code: Select all

#!/bin/bash

echo "I'm sorry $USER, but I can't  do that. I don't think it is a good idea to
$*." | sed s/my/your/ig | sed s/mine/yours/ig | sed s/me/you/ig
hehehe
Last edited by Master of Reality on Tue Nov 04, 2003 9:10 pm, edited 2 times in total.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

But a "sed s/you/me/ig | sed s/me/you/ig" will not do what you want. That is, if there is a "you" in your params it will be changed to "me" and then back to "you". Same goes for all the others yours->mine->yours etc. Seems like a waste of CPU to me. :) Actually that's only half right. It would work the way you want if you had a "me" in your params but not if you had a "you" in your params.

Post Reply