Bash question

Discuss Programming

Bash question

Postby Master of Reality » Tue Nov 04, 2003 3:13 pm

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?
Master of Reality
guru
guru
 
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Postby Void Main » Tue Nov 04, 2003 3:20 pm

Code: Select all
echo $* | sed s/my/your/ig


Is using sed cheating?
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby Master of Reality » Tue Nov 04, 2003 4:17 pm

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
Master of Reality
guru
guru
 
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Postby Void Main » Tue Nov 04, 2003 4:29 pm

Get rid of the leading "/", but why do you need the same thing twice? My example acounts for both my->your and myself->yourself.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby Master of Reality » Tue Nov 04, 2003 4:50 pm

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

Postby Master of Reality » Tue Nov 04, 2003 4:53 pm

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.
Master of Reality
guru
guru
 
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Postby Void Main » Tue Nov 04, 2003 5:02 pm

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.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests