LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2010, 02:25 PM   #1
Abid Malik
LQ Newbie
 
Registered: Sep 2010
Posts: 25

Rep: Reputation: -1
Question 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

Last edited by Abid Malik; 10-21-2010 at 10:34 AM.
 
Old 10-20-2010, 02:42 PM   #2
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Rep: Reputation: 15
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.
 
Old 10-20-2010, 02:42 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
That depends at least partially on:

a) what language you're using
b) what data type the variable is
 
Old 10-20-2010, 03:42 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Did you really read the post?

The OP said "bash shell script".
 
Old 10-20-2010, 04:01 PM   #5
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
so, what you've done so far? any code to show? we're not going to write it for you
 
Old 10-20-2010, 04:23 PM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by MTK358 View Post
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.
 
1 members found this post helpful.
Old 10-20-2010, 04:34 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by crts View Post
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.
 
Old 10-21-2010, 02:43 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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
 
Old 10-21-2010, 06:59 AM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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.
 
0 members found this post helpful.
Old 10-21-2010, 08:27 AM   #10
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
If that is the case, then:
var=abcdef
var=$(echo $var|rev)
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
swaping HDD sirscott Linux - Hardware 4 08-21-2009 02:33 AM
PII 400mhz swaping in Red Hat 9 error404 Linux - Hardware 9 11-14-2003 12:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration