LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   swaping (https://www.linuxquestions.org/questions/programming-9/swaping-839360/)

Abid Malik 10-20-2010 02:25 PM

swaping
 
Hello!
it is linux bash shell script language.
i have a variable

var=abcdef

now i want to replace the a with z, b with y, c with x.
how can i do this.
that the new values of variable will be

var=zyxwvu

gothrog 10-20-2010 02:42 PM

Ahhh.... What programming language? Does it matter?

You directly stated your problem, but did not define a configuration set for the problem to be on top of.

paulsm4 10-20-2010 02:42 PM

That depends at least partially on:

a) what language you're using
b) what data type the variable is

MTK358 10-20-2010 03:42 PM

Did you really read the post?

The OP said "bash shell script".

HasC 10-20-2010 04:01 PM

so, what you've done so far? any code to show? we're not going to write it for you

crts 10-20-2010 04:23 PM

Quote:

Originally Posted by MTK358 (Post 4133976)
Did you really read the post?

The OP said "bash shell script".

Look at the 'last edit' time of the OP. My guess is that the bash part was added in the OP after the first two responses.

MTK358 10-20-2010 04:34 PM

Quote:

Originally Posted by crts (Post 4134029)
Look at the 'last edit' time of the OP. My guess is that the bash part was added in the OP after the first two responses.

Didn't notice that.

gnashley 10-21-2010 02:43 AM

The desired result seems to be poorly stated. According to this:
"replace the a with z, b with y, c with x"
the end result should be:
$var = zyxdef
This is simply the reverse of the original:
var=fedcba

MTK358 10-21-2010 06:59 AM

Maybe he meant that is the string were the alphabet, a would become z, etc. I agree that it's a impossible to understand and dumb way of saying "reverse a string", but maybe.

gnashley 10-21-2010 08:27 AM

If that is the case, then:
var=abcdef
var=$(echo $var|rev)


All times are GMT -5. The time now is 04:36 PM.