Page 1 of 1

{ in string

Posted: 08 Mar 2017 07:00
by acerzw
How can I include a { char in a Widget text element without it being considered the start of a string inline expression?

Re: { in string

Posted: 09 Mar 2017 20:56
by Martin
Hi,

A widget text element should not do anything with a single opening curly brace, it just gets more complicated when an opening and closing brace are used in the text.
When you have an opening and closing curly brace, you can use following syntax when you want to avoid that Automagic replaces variables in a text like {text}:
{'{text}'}

Regards,
Martin

Re: { in string

Posted: 09 Mar 2017 22:02
by piskor
Hello Martin,

In one of my flow I tried to execute root command:
dumpsys batterystats | grep -m1 'Screen on:' | awk -F: '{print $2}' | awk -F" " '{print $1,$2}'
but here AM also had problem with { sign and tried to interprets {print as some unknown variable
For now I am using other command, but it would be nice to know how to use this sign if it is possible

Re: { in string

Posted: 12 Mar 2017 21:20
by Martin
Hi,

You can use the same procedure to escape the curly braces.

Variant 1 (entire command enclosed in {'...'}, single quotes escaped with a backslash):
{'dumpsys batterystats | grep -m1 \'Screen on:\' | awk -F: \'{print $2}\' | awk -F" " \'{print $1,$2}\''}

Variant 2 (each 'variable' escaped on it's own within {'...'}):
dumpsys batterystats | grep -m1 'Screen on:' | awk -F: '{'{print $2}'}' | awk -F" " '{'{print $1,$2}'}'

Regards,
Martin

Re: { in string

Posted: 16 Mar 2017 16:01
by piskor
Thank you very much for explanation.
It works

BR, piskor