Percent sign doubling in cmd-line

Please report only one bug per message!

Moderators: Stefan2, white, sheep, Hacker

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-08, 13:03 UTC

I'd prefer solution 1.
1. Always replace %% by %, and leave the env. var in between alone, e.g.
a%%b -> a%b
a%%b%%c -> a%b%c
Pro: It's the easiest to explain and understand (also why a specific case wouldn't work).
Contra: Copy&paste of paths containing double percent signs themself would need editing the path from two to four percent signs - no problem IMO (I think in real paths double percent signs are quite rare).

Solution 2 and 3:
How would "a%%b%%c%%d" be handled?
I think it's more difficult also for the user, and hard to find mistakes here.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-08, 13:32 UTC

I would think the best route would be to do normal environment variable expansion, like it is done in cmd shell. If you've used "%" and "^" in your filenames then you are used to the hassle doing so creates ;)
C:\%FOO%
C:\^FOO^
C:\
cd ^FOO^ ---> More?
cd ^^FOO^^ ---> C:\^FOO^
SET FOO=FOOBAR
cd %FOO% --> The system cannot find the path specified.
Putting a Caret at any place within that string, will nullify its "value" as an environment variable (except at the beginning).
So cd %^FOO%
Or cd %F^OO%
etc, will put you into the actual %FOO% folder.

The only change this would make, is to requiring double carets when you want to use 1 (and should possibly be applied to both "command" and "parameters" to make everything _consistent_). I doubt that would be a problem for most - and should be easily understandable. Without overloading the %%, $$, //, or \\ characters more.

^ In command prompt means the next character is literal.
You need to use it for escaping > < | redirection in batch scripts, and to escape quotes for various ported linux tools, ie gawk, sed etc.

So when TC parses the string, it would ignore single carets, treat any single next char as literal and treat it as an automatic fail for attempting to expand environment variables.
Thus the following in parameters field: "%ProgramFiles%\%^FOO%\%FOO%\"
TC would expand "%ProgramFiles%", it would not expand %^FOO%, and it would expand %FOO%

So the string would become C:\Program Files\%FOO%\FOOBAR
(given the environment variable for FOO=FOOBAR).

If you wanted to send a literal %ProgramFiles%, then
%^ProgramFiles%, unless the intention is to continue requiring double percents to send a single percent... which I would recomend against. It overloads the character which TC already uses for its own parameters.
If you want to send a literal % then, ^%

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2009-09-08, 15:26 UTC

Hmm, adding one more character (^) just moves to problem to yet another character - the ^ sign is also an allowed character in file names...
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8282
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2009-09-08, 15:52 UTC

I think better case is 1 because it gives exact rule for any situation.

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-09, 22:49 UTC

Fixed in TC 7.50. :)
Very nice, thanks.

Edit: Too early, sorry. The correct display I found was in parameters field, not in command field yet.
Last edited by StatusQuo on 2009-09-11, 15:20 UTC, edited 1 time in total.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

User avatar
Samuel
Power Member
Power Member
Posts: 1866
Joined: 2003-08-29, 15:44 UTC
Location: Brandenburg, Germany
Contact:

Post by *Samuel » 2009-09-10, 05:04 UTC

There has been nothing changed on this one or am I missing something?

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2009-09-10, 10:15 UTC

Indeed it hasn't been changed yet, I wanted to get your opinions first...
Author of Total Commander
http://www.ghisler.com

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-10, 10:24 UTC

I don't see how the previous suggestions of doubling %% would work when dealing with both environment variables, TC parameters and needing to sometimes send a literal % percent sign.

How would %%%S be parsed? A literal % and then expand %S ?
How to send a literal percent and a character that TC uses as a parameter?
%%%%S ? That is a mess compared to
%^S

But apparently no one else seems to agree so the point must be moot!
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.

Postkutscher
Power Member
Power Member
Posts: 556
Joined: 2006-04-01, 00:11 UTC

Post by *Postkutscher » 2009-09-10, 15:34 UTC

StatusQuo wrote:I'd prefer solution 1.
1. Always replace %% by %, and leave the env. var in between alone, e.g.
a%%b -> a%b
a%%b%%c -> a%b%c
Pro: It's the easiest to explain and understand (also why a specific case wouldn't work).
Contra: Copy&paste of paths containing double percent signs themself would need editing the path from two to four percent signs - no problem IMO (I think in real paths double percent signs are quite rare).
I would say, double percent signs in real paths are very rare. So, IMO, 1.

User avatar
Samuel
Power Member
Power Member
Posts: 1866
Joined: 2003-08-29, 15:44 UTC
Location: Brandenburg, Germany
Contact:

Post by *Samuel » 2009-09-10, 15:54 UTC

I would say, double percent signs in real paths are very rare. So, IMO, 1.
Agree.

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-11, 15:30 UTC

2Balderstrom
What I would expect from solution 1 (having "file.ext" marked):

Code: Select all

%%S%%     => %S%
%%%S%%    => %file.ext% (expanded %S)
%%%%S%%%% => %%S%%
So, to make one percent sign literal, there is one % to add.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-11, 16:32 UTC

%S is a TC parameter, %S% is a possible Environment variable. So then, how does it expand
%S% ?
Or %S%%P%, is that %S% %P% ? or %S_%%_P%

Or %S%P, is that %S%_P ? or %S_%P
Or %%S%P

Really this is something I will never need, but I find it very odd that people believe that mixing together 2 separate syntaxes and adding in more percent signs to distinguish between them is a good thing... when they both already require percent signs.
Environment variables require %enclosed% percents
and TC Parameters a %single percent.

There ought to be a way to specify something is an environment variable or it is not, without the vagaries entailed with tacking on multiple percents.

%S%^%S == Environment variable "Foobar" + Parameter "File.ext"

%^S%^%S == Literal "%S%" + Parameter "file.ext"

As opposed to, %S%%S%P
Which is which? %S%_%S_%P ? or %S_%%_S_%P
Or %S%%%S%P is... %S%_%%_S_%P ? or %S_%%_%S_%P

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-11, 18:31 UTC

Balderstrom wrote:%S is a TC parameter, %S% is a possible Environment variable
Not in the same line:
command field expands environment vars only,
parameters field only internal vars (my above example is wrong here, too).
Balderstrom wrote:%^S%^%S == Literal "%S%" + Parameter "file.ext"
How would you encode a literal "^" then, e.g.
literal "%S%^" + Parameter "file.ext"?
Balderstrom wrote:As opposed to, %S%%S%P
Which is which?
In command field: %S% + %S% + literal "P".
in parameters field: %S + literal "%S" + %P

The syntax is still different in both fields then, but currently a literal "%foo%" seems to be impossible in command field.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-11, 23:21 UTC

AH, right. I got turned around in the discussion, MVV talked about ENV Vars in the parameters field earlier.

I send a number of things thru MultiFileOpen.cmd for the ButtonBar Command, thus can get a literal %Foo%, (if I needed it), with %^Foo%

But if yer going directly to a non-commandLine .exe then, %^Foo% gets interpreted as actually, %^Foo%, heh.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.

Post Reply