Use of %? in unix -


i new unix, can please tell me purpose of '%?' in below command:

-bash-3.2$ sample=test123 -bash-3.2$ sample=${sample%?} -bash-3.2$ echo $sample test12 

i can see removing last character can remove many characters want, example 3 charactes etc.

it's pattern matching operator, meaning "if pattern matches end of variable's value, delete shortest part matches , return rest". since ? matches "any single character", last character removed.

so if want remove 3 characters, need replace ? expression matches 3 characters instead of one.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -