I’ve a string variable and I want to remove the last character of it.
For example: pass from “testing1” to “testing”.
How can I do this in KSH?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
output
The
${var%?}is a parameter editing feature. The ‘%’ says remove from the right side and expects a pattern following. The pattern could be in your example case just the char ‘1’ (without the quotes). I am using the wild-card char ‘?’ so that any single character will be removed. You can use the ‘*’ char to indicate all chars, but typically you want to ‘bundle’ that with some preceding chars, with your exampleecho ${var%i*}would give you justtestas a result. There are also ‘%%’ variants on this AND ‘#’ and ‘##’ that start from the left side of the string.I hope this helps.