{ in string

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
acerzw
Posts: 39
Joined: 10 May 2015 13:38

{ in string

Post by acerzw » 08 Mar 2017 07:00

How can I include a { char in a Widget text element without it being considered the start of a string inline expression?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: { in string

Post by Martin » 09 Mar 2017 20:56

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

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

Re: { in string

Post by piskor » 09 Mar 2017 22:02

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
Regards, piskor

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: { in string

Post by Martin » 12 Mar 2017 21:20

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

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

Re: { in string

Post by piskor » 16 Mar 2017 16:01

Thank you very much for explanation.
It works

BR, piskor
Regards, piskor

Post Reply