There's two different ways of handling variables with IMC. One way is to define a variable that you'll get asked for when you go to run the script. This is OK for a script that you want to run regularly against different devices, and don't mind manually entering a value each time you run it.
But for your case, I think you're looking more at using "MIB parameters"
2.Input MIB parameter, according with $(mibName|mibVariable|index).
For example: $(H3C-SYS-MAN-MIB|h3cSysImageSize|65537) or $(H3C-SYS-MAN-MIB|h3cSysImageSize|@(H3C-SYS-MAN-MIB|h3cSysReloadImage|65536)).
However...you might not be able to find a MIB parameter that matches the last octet.
If you can't, then you might be better off deploying a script that performs more complex processing on the switch itself. Depending on what your device can do, that might be Python or TCL.