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

node.js - StackOverflow API not returning JSON -

ios - Apple Push Notifications + TestFlight + Enterprise wildcard provisioning profile -

android - Drag and drop in ScrollView -