Ask Your Question

Change replace character in string and add strings?

asked 2014-09-29 17:07:11 -0600

GLN gravatar image

updated 2014-09-29 17:49:41 -0600

ramindk gravatar image

I have a software to deploy where the installer for version 5.3.7 has 537 in its name (which is a parameter to the class). Its full name will be something like mysoftware-537-linux-ia32.bin or mysoftware-537-linux-x86_64.bin depending on the architecture.

I have this in my class:

softprefix = "mysoftware-"
version = "5\_3\_7"
softsuffix = "-linux-x86_64.bin"    # or  -linux-ia32.bin depending on the OS

How do I replace the "_" with "." in the string 5_3_7 and make the version 5.3.7?

Also how do I concatenate the strings? installer = $softprefix+$version+$softsufix doesn't seem to work.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-09-30 02:48:12 -0600

jonn gravatar image

For the string replacement, try regsubst:

$softprefix = 'mysoftware-'
$version = '5_3_7'
$softsuffix = '-linux-x86_64.bin' 

$dottedversion = regsubst($version, '_', '.', 'G')

The 'G' says to replace globally across the string, not just the first match. (And remember that variable names in Puppet start with a '$' sign :)

Concatenating strings is done inside double quotes, like this:

$installer = "${softprefix}${version}${softsuffix}"
edit flag offensive delete link more


Thanks John. This works great with one change regsubst($version,'\.', '_', 'G') GLN

GLN gravatar imageGLN ( 2014-09-30 09:50:37 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-09-29 17:07:11 -0600

Seen: 11,083 times

Last updated: Sep 30 '14