# Deciphering strings or variable values

**URL:** <https://community.unix.com/t/deciphering-strings-or-variable-values/248011>\
**Category:** Shell Programming and Scripting\
**Created:** [August 27, 2009, 11:18am UTC](https://community.unix.com/t/deciphering-strings-or-variable-values/248011 "2009-08-27T11:18:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyberfrog](https://community.unix.com/letter_avatar/cyberfrog/32/6_449c533f586939b6e5f246632a46421f.png) [@cyberfrog](https://community.unix.com/u/cyberfrog)\
**Post date:** [August 27, 2009, 11:18am UTC](https://community.unix.com/t/deciphering-strings-or-variable-values/248011/1 "2009-08-27T11:18:47Z")

</div>

Hi,

I have a script at the moment of which reads in simply what the latest version is within a folder i.e. v001, v002, v003 etc and then stores this latest version in a variable i.e. $LATEST would echo v003. I have then cut this string so that I only consider the 003 part. I would then like to increment this to 004 and then put the v back in front of it again i.e. v004. What is the easiest way of doing this?

Cheers

CF

---

<div class="post-metadata">

**Author:** ![chipcmc](https://community.unix.com/letter_avatar/chipcmc/32/6_449c533f586939b6e5f246632a46421f.png) [@chipcmc](https://community.unix.com/u/chipcmc)\
**Post date:** [August 27, 2009, 11:45am UTC](https://community.unix.com/t/deciphering-strings-or-variable-values/248011/2 "2009-08-27T11:45:02Z")

</div>

Example:

```nohighlight
valor=0003
aux=`printf %.4d $(expr $valor + 1)`
echo "[$aux]"

```

i supose you want 4 digits for this motiv is .4d

---

<div class="post-metadata">

**Author:** ![cyberfrog](https://community.unix.com/letter_avatar/cyberfrog/32/6_449c533f586939b6e5f246632a46421f.png) [@cyberfrog](https://community.unix.com/u/cyberfrog)\
**Post date:** [August 27, 2009, 11:55am UTC](https://community.unix.com/t/deciphering-strings-or-variable-values/248011/3 "2009-08-27T11:55:15Z")

</div>

Great it worked and how do you then append a letter in front of it so valor = v00004?

---

<div class="post-metadata">

**Author:** ![chipcmc](https://community.unix.com/letter_avatar/chipcmc/32/6_449c533f586939b6e5f246632a46421f.png) [@chipcmc](https://community.unix.com/u/chipcmc)\
**Post date:** [August 27, 2009, 12:01pm UTC](https://community.unix.com/t/deciphering-strings-or-variable-values/248011/4 "2009-08-27T12:01:16Z")

</div>

change this line

```nohighlight
aux=`printf v%.4d $(expr $valor + 1)`

```
