Programming and Scripting :: Problem with variable assignment



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

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.

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.

original here.