View Issue Details

IDProjectCategoryView StatusLast Update
0003630OpenFOAMBugpublic2021-02-17 11:01
Reporterharald Assigned Tohenry  
PrioritylowSeverityminorReproducibilityalways
Status closedResolutionno change required 
PlatformGNU/LinuxOSUbuntuOS Version18.04
Product Versiondev 
Summary0003630: foamDictionary -set in combination with Regex
DescriptionfoamDictionary can handle Regex entries without escaping special characters in combination with the options -value and -remove. However, this does not work for the option -set. Is it possible to remove the need for escape characters also for the -set option?
Steps To Reproduce# Copy the pitzDaily case to the cwd
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily/ .

# Display all SIMPLE/residualControl entries
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl

# Read p
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/p
# Do the same with the value-option
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/p -value
# Set p to 0.123
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/p -set 0.123
# Remove p
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/p -remove

# Try the same with a Regex-entry
# Read the entry
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/"(k|epsilon|omega|f|v2)"
# Do the same with the value-option
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/"(k|epsilon|omega|f|v2)" -value
# Setting a new value without escaping the special characters results in an error
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/"(k|epsilon|omega|f|v2)" -set 0.00456
# Setting a new value requires escaping all special characters
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/\"\(k\|epsilon\|omega\|f\|v2\)\" -set 0.00456
# Remove "(k|epsilon|omega|f|v2)"
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl/"(k|epsilon|omega|f|v2)" -remove

# Display all remaining entries
foamDictionary pitzDaily/system/fvSolution -entry SIMPLE/residualControl
TagsNo tags attached.

Activities

henry

2021-02-16 14:46

manager   ~0011882

Because you want to change an entry with a '"' delimited keyword you need to pass in the '"' which the command-line parsing is stripping off by default, i.e.

 foamDictionary system/fvSolution -entry SIMPLE/residualControl/'"(k|epsilon|omega|f|v2)"' -set 0.00456

and with this you do not need to escape the individual elements of the string.

harald

2021-02-17 07:27

reporter   ~0011883

Great this works perfectly. However, vice versa it only works for the -remove option. If you apply the same to the -value option, you get an error. This is fine for me, since I now know how it works. Still, is it possible to have a consistent behavior where either single quotes are always or never needed for regular expressions?

foamDictionary system/fvSolution -entry SIMPLE/residualControl/'"(k|epsilon|omega|f|v2)"' -set 0.00456
foamDictionary system/fvSolution -entry SIMPLE/residualControl/'"(k|epsilon|omega|f|v2)"' -value
foamDictionary system/fvSolution -entry SIMPLE/residualControl/'"(k|epsilon|omega|f|v2)"' -remove

harald

2021-02-17 07:38

reporter   ~0011884

Just now I realized that I need to use another pair of single quotes with the -value option in combination with regular expressions. Perhaps I do not know enough about command parsing, and, therefore, the different behavior of this one option seems a little strange to me.

foamDictionary system/fvSolution -entry SIMPLE/residualControl/''"(k|epsilon|omega|f|v2)"'' -value

henry

2021-02-17 08:13

manager   ~0011885

> Still, is it possible to have a consistent behavior where either single quotes are always or never needed for regular expressions?

Can you provide a patch which changes foamDictionary to how you want it to behave or fund this development?

harald

2021-02-17 10:16

reporter   ~0011886

Unfortunately, I cannot do either. I try to get more involved, but I am not yet in a position to provide a patch or decide on funding.

Issue History

Date Modified Username Field Change
2021-02-16 13:25 harald New Issue
2021-02-16 14:46 henry Note Added: 0011882
2021-02-17 07:27 harald Note Added: 0011883
2021-02-17 07:38 harald Note Added: 0011884
2021-02-17 08:13 henry Note Added: 0011885
2021-02-17 10:16 harald Note Added: 0011886
2021-02-17 11:01 henry Assigned To => henry
2021-02-17 11:01 henry Status new => closed
2021-02-17 11:01 henry Resolution open => no change required