linux - How to read directelly the last charachter in a string in bash? -


i have following string

string="anyanyanay" 

how can read last charachter in string?

use below script

#!/bin/bash string="anyanyanay" echo ${string#${string%?}} 

output : y

${string%?} removes last character string.

${string#<character>} removes characters string starting.

in case

${string%?} = anyanyana

${string#${string%?}} = ${string#anyanyana} = y


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -