In all of my coding time, I have never ever used this. It throws a error in real simple case. So, how do you use it and why would it better than other approach?
It is used to force an expression to be considered as double-quoted.
Here is a typical use case. Imagine you have a string that potentially contains commas.
In GâMIC, a comma can be either :
- A regular comma, that is ascii code 44. Thatâs actually the separator used when specifying command arguments.
- A âstring-encodedâ comma, that has a different ascii code.
Sometimes, you want to specify a single command argument as a string that may contain regular commas. In this case, using {``$str} is the solution:
foo :
400,400
str="Hello, friends!" # will work, comma is already considered as a string character
str=Hello,\ friends # won't work, comma is a regular comma
5,1,1,1,x str={^} # won't work, comma is a regular comma
t $str,0.5~,0.5~,48,1,1 # won't work for the problematic cases
t {``$str},0.5~,0.5~,48,1,1 # will always work
Just to confirm @Reptorian. Are you talking about two backticks and not the double quotes in the title? Which code snippet piqued your curiosity?
@David_Tschumperle Thanks, I will see where I can use this.
@afre Backticks. I was reviewing the documentary, and this one pisque my interest.
I found this thread after having problems with -text a string on an image. I did the test above and problem persists, see below, running on a bash shell,
gmic 400,400 str=âHello, friends!â t {``$str},0.5~,0.5~,48,1,1
[gmic]./ Start GâMIC interpreter (v.3.5.6).
[gmic]./ Input black image at position 0 (1 image 400x400x1x1).
[gmic]./ Set local variable âstr=Hello, friends!â.
[gmic]./ *** Error *** Item substitution â{}â: Empty braces.
The problem I had was a bit different, my string had a space, as in âstr=Hello worldâ, and -text didnât write anything, I just get a plain black image (it works when string has no spaces),
gmic 400,400 t âHello worldâ,0.5~,0.5~,48,1,1
[gmic]./ Start GâMIC interpreter (v.3.5.6).
[gmic]./ Input black image at position 0 (1 image 400x400x1x1).
[gmic]./ Draw text âHello world,0.5~,0.5~,48,1,1â at position (0,0) on image [0], with font height 16, opacity 1 and color (default).
[gmic]./ Display image [0] = â[unnamed]â.
[0] = â[unnamed]â:
size = (400,400,1,1) [625 Kio of float32].
data = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ⌠,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0).
min = 0, max = 0, mean = 0, std = 0, coords_min = (0,0,0,0), coords_max = (0,0,0,0).
[gmic]./ End GâMIC interpreter.
I tried different shells, got to work with csh/tcsh using different syntax,
gmic 400,400 str=âHello worldâ t {â$strâ},0.5~,0.5~,48,1,1
What am I missing?
Thanks for any help.
The problem with that is the bash shell has its own substitution mechanism, so you need to take care both at GâMIC and bash at the same time.
And things can become quickly a bit convoluted.
In your case, you should type for instance:
$ gmic 400,400 'str=\"Hello, friends!\"' t '{``$str}',0.5~,0.5~,48,1,1
(single quotes have been added here and there, as well as backslashes, but just to âdisableâ bash substitution, itâs not a GâMIC thing!).
To get rid of the bash substitution aspect, you should put your command into a GâMIC command file:
# File 'foo.gmic'
foo :
400,400
str="Hello, friends!"
t {''$str},0.5~,0.5~,48,1,1 # $str would actually suffice here rather than {''$str}
then:
$ gmic foo.gmic foo
Thanks, problem resolved.
Sometimes I just need a quick bash call to get what I need so no foo.gmic, but I certainly should make this a good practice.
By the way, I needed the two back quotes on foo.gmic to get it to work, just $str didnât work, as suggested in your commented line above.
Correction: t $str,0.5~,0.5~,48,1,1 works but not t {$str},0.5~,0.5~,48,1,1. I should have read the entire line.