Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Problem with variable assignment< Next Oldest | Next Newest >
rlr0304 Offline





Group: Members
Posts: 8
Joined: Jan. 2007
Posted: Jan. 18 2007,07:19 QUOTE

I'm trying to assign the results of ${myStr:(-1)} (which returns the last character of the myStr) to a variable.  I've tried:

  lastChar=${myStr:(1)}
  lastChar='${myStr:(1)}'
  lastChar=`${myStr:(1)}`
  lastChar="${myStr:(1)}"

and a number of other variations.  I've haven't been able to get it to work.

Can someone please help me out?

TIA,

Richard
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 18 2007,13:18 QUOTE

If this is Bash, Your first attempt should have worked:
lastChar=${myStr:(-1)}
Another option is to add a space after the colon:
lastChar=${myStr: -1}

If you're using some other shell other than Bash, this probably won't work, and you may need to pipe your variable through cut or some other program.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
rlr0304 Offline





Group: Members
Posts: 8
Joined: Jan. 2007
Posted: Jan. 19 2007,08:46 QUOTE

Thanks for the reply.  Turned it part of my problem was a typing error that I didn't see despite reading it a hundred times.
Back to top
Profile PM 
2 replies since Jan. 18 2007,07:19 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Problem with variable assignment

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code