How to escape a doublequote-sign inside a (tau) prolog string? - tau-prolog

I guess there must be an easy answer to this, but I just haven't been able to find it -
I want to include double-quote signs inside tau-prolog strings.. how to do it?
When I try entering it into the Tau-Prolog sandbox (http://tau-prolog.org/sandbox/) I get the following interaction:
A = "hello there, \"world\"".
error parsing query: error(syntax_error(unknown_escape_sequence),[line(1),column(4),found('"hello there, \\"')])
Any ideas?
Where did I (stupidly) misunderstand things? :)
PS - it's not only a problem in the sandbox - if try to run a Tau-Prolog program (in the browser), and use a double-quote character anywhere inside a string I get the same parsing-problem.

Related

Bash variable does not allow a directory name to be assigned to it

I want to create the following variable in Bash:
PATHTOMYDIR=/fshare/users/myusername/
(basically, a variable with a string inside: the path to my directory, where I have my data, that later on can be included in some scripts to generate folders inside that directory, for example).
The concrete problem is: when I typed that line of code I got the following error message:
-bash: /fshare/users/myusername: Is a directory
Hence, I wanted to ask: does Bash not allow a variable to contain the name of a path? I thought it was possible, so I assume I am missing something else here. I googled the error message but I did not find any post at any forum with this case.
I had a space between the "=" and the first "/" of the path.
This makes an error:
PATHTOMYDIR= /fshare/users/myusername/
This is correct:
PATHTOMYDIR=/fshare/users/myusername/
It seems that space makes the difference. Thank you #AIG and #Jason !
EDIT: #Jason pointed out that is good practice to use commas, so a more correct form would be:
PATHTOMYDIR="/fshare/users/myusername/"

Using the `$` character in `ruby_block` in chef

I want to use the following code in my recipe for ruby_block, but it's not working because of the '$'. The code cannot find $NAME, but it can find NAME. Can you give me a solution?
file.search_file_replace_line("DEFAULT=/etc/default/$NAME","DEFAULT=/etc/default/tomcat7")
search_file_replace_line expects regex as the first argument. And dollar sign is a special symbol within the regular expressions, it means end of the line, basically. So you have to properly escape it if you really want to replace it with something.
This will do the job:
file.search_file_replace_line("DEFAULT=/etc/default/\\$NAME","DEFAULT=/etc/default/tomcat7")

Robot: Backslash in EXECDIR, Windows path

Underlying problem: I want to enable running robot tests using selenium 2 in a portable Firefox that's stored within EXECDIR.
${firefox_binary}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_binary'].FirefoxBinary('${EXECDIR}${/}Firefox${/}App${/}Firefox${/}Firefox.exe') sys, selenium.webdriver
${firefox_profile}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile('${EXECDIR}${/}Lib${/}SeleniumFirefoxProfile') sys, selenium.webdriver
Create Webdriver Firefox firefox_binary=${firefox_binary} firefox_profile=${firefox_profile}
That works fine if, instead of ${EXECDIR}, I use the actual path.
EXECDIR is something like C:\Users\bart.simpson\workspace\projectname here. The issue is that a backslash, when followed by the b, is converted to the ASCII backslash character. The test log then says:
Evaluating expression 'sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile('C:\Users\bart.simpson\workspace\projectname\Lib\SeleniumFirefoxProfile')' failed: OSError: [Errno 20047] Unknown error: 20047: 'C:\\Users\x08art.simpson\\workspace\\projectname\\Lib\\SeleniumFirefoxProfile'
Of course I've tried using ${fixedExecDir}= Replace String ${EXECDIR} '\' '/' and such, but nothing ever changes the outcome.
Ideas? Thanks.
Try treating the path as a raw string literal, by putting an "r" before the quote immediately before ${EXECDIR}:
${firefox_binary}= Evaluate ....FirefoxBinary(r'${EXECDIR}${/}Firefox...')
This should work because the robot variables are substituted before the string is passed to python, so the python interpreter only ever sees the complete string.
If you are unfamiliar with python raw string literals, see this question:
What exactly do “u” and “r” string flags do in Python, and what are raw string literals?

Bash shell, trying to create and evaluate a mask

I'm trying to create a mask and use the bitwise operator "&" to compare to another variable and see the output. Let there be code:
mask=00000
mesk=00010
mosk=$mask&$mesk
echo $mosk
echo meec
I'm trying to expand this functionality to be able to have more characters (different error/success codes), but those lines just don't work: Executing the script will print an empty line, then "meec".
I came from an object oriented programming background, and although I've read through several documents on this subject, it seems there's something I'm missing.
Any help would be appreciated.
Edit: For some reason, turns out the code doesn't work, it says "command 00010 not found" >_>
It's because usually the & character in the shell is the modifier to put a command in the background.
You have to use Arithmetic Expansion of Bash (for example) for it to work:
mosk=$(($mask & $mesk))

windows grep redirect output to file

I'm working on windows and I want to find all the strings beetwen quotes, from a directory. For example, if I have this:
string s = "Hello World!"
The grep command should return me "Hello World!".
Here is how I do this:
grep -Roe \"[^\"]*\" directory
I need to redirect the output to a file but when I redirect the output, like this "grep -Roe \"[^\"]*\" directory > log" I get the following errors:
>: Invalid argument
log: No such file or directory
Do you know how can I solve this and redirect the output?
This is a very old question, and by now the OP has probably solved it... but for posterity, it's worth noting that the issue is to do with the compiler conventions (see this question, and find the answer headed "You aren't using a Unix shell. Quoting is different").
As you've discovered, while your expression will work fine at the command line, when it is used in conjunction with a redirect it gets parsed wrongly.
The solution is to escape the double quotes with a caret (^), not a backslash (\). And you need to escape the caret as well (with a caret). You should also enclose the entire search expression in single quotes.
Reformulating your command using caret-escaping (and enclosing in '') yields
grep -Roe '^"[^^^"]*^"' directory > log
I use this quite a bit to get style attributes from legacy HTML files (basically stuff written by a former coder who didn't believe much in separating content from presentation) - in which case I use
grep -iown 'style=^"[^^^"]*^"' index.html > styles.txt
It works like a charm.
Imagine a code repository where every in HTML file, even the p tags go something like <p style="margin-left:20px;margin-top:20px; font: normal 12px Arial; color#FFFFFF">. Sheesh.

Resources