There is some problem with Geany's context action command that is revealed by the following example.
Let's make a simple /home/me/sh1 executable file containing: ``` 1 #! /bin/bash 2 echo "$1" "$2" "$3" 3 read ``` and set the context action command as: ` xterm -e /home/me/sh1 $2 $3 "%s"`
Now not going too far, let's select line #2 of our sh1 and run the context action command. We'll get in xterm: ` $2 $3 echo $1 $2 $3` while indeed we waited the following: ` $2 $3 echo "$1" "$2" "$3"`
To get it we should select the text with quotes escaped: ` echo "$1" "$2" "$3"`
Reason of all this mess is that Geany doesn't escape quotes in itself. The internal Geany code swallows quotes of %s.
Moreover, if we select "$ in our text then we'll get nothing. By this we'll totally confuse Geany.
Any odd number of " in selected text will do the same.
By the way, to process this sentence with context command we should write it as: ` Any odd number of " in selected text will do the same.` but writing and selecting it quoted: ` "Any odd number of " in selected text will do the same."` we'll get ` $2 $3 Any` (after internal stripping all non-escaped quotes $3 parameter of sh1 will get "Any", $4 "odd", $5 "number" ...).
All this is not so good. Geany should not modify any selected text any way. It's for us stupid users to use any number of quotes and other stuff in processed text.
---------
2nd issue is in "Compile/ Build/ Run settings".
If we set the Run command (let it be so dull, heh): ` xterm -e /home/me/sh1 $2 $3 "%s"` and press F5, all we get in xterm is: ` %s` Geany swallows all $ when they are followed by a number or a letter. It takes them internally for some parameters and substitutes them in Run command with spaces.
Quoting them as in ` xterm -e /home/me/sh1 "$2" "$3" "%s"` doesn't help as well.
Version of Geany and OS and versions of Glib and GTK?
If we set the Run command (let it be so dull, heh):
xterm -e /home/me/sh1 $2 $3 "%s" and press F5, all we get in xterm is: %s
xterm runs the command in a shell, which substitutes $2 and $3 with nothing since they are undefined.
The other problems may be variations of this I suspect or of the several levels of command encoding/decoding that occur.
The internal Geany code swallows quotes of %s.
Yes, this allows %s to contain spaces without being split into several arguments.
To expand, on *ix systems commands are not passed to the system as a single string as they are input in build or context command settings. The system takes an array with each argument a separate string. So Geany has to split the command into arguments, which it does using a Glib function that mimics the way the shell splits command strings into arguments. So like the shell things in quotes are made a single argument, even if they contain spaces, and the quotes are removed.
But since xterm runs the command in a shell, it has to re-combine the arguments to pass a string to the shell as if it had been typed at the command line, and the shell then splits it apart again. So as you can see there is plenty of scope for arguments boundaries to get mixed up.
Great thanks for your answers!
My Geany is Geany 1.29 on Debian 9.3.
Excuse me for being short but it's not xterm but Geany swallows $everything.
xterm is only for example.
I run (with Geany's F5) a program different from xterm and hope it would get my lovely $everything.
However I get " " instead.
O tempora, o mores! After all I included this awful $everything in the Run command!
Well, I try and add "-" around $everything, i.e. I pass -$everything- to a program of Run command and got -- instead of -$everything-
And yes, far from calling xterm (and similars), Geany doesn't take %s internally if %s contains odd number of ". Geany in this case puts an error message in its statusbar.
Nevertheless, with great regards for Geany and Geany team forever yours Alex Plotnikov
Среда, 14 марта 2018, 0:54 +03:00 от elextr notifications@github.com:
Version of Geany and OS and versions of Glib and GTK? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub , or mute the thread .
Best regards & bye! Yours A.PL.simple
I run (with Geany's F5) a program different from xterm and hope it would get my lovely $everything.
And again its the shell thats swallowing it, commands execute in a shell, try typing `echo $2 "$3" -$4-` at the command line without a Geany in sight and the shell will do what you told it to (not what you want it to), substitute the relevant parameters (which are empty) for the $n and so your beautiful $n is masticated out of existence by the SHELL.
You need to shell escape the poor innocent `$` that is egregiously eaten by the shell with a backslash which is a substantial meal for a shell and satiates its hunger and it leaves the `$` alone.
Closed #1801.
"@commands execute in a shell," - Oh, it's true and explains all this issue. "Afraid of this!":) Thank you very much.
github-comments@lists.geany.org