[SOLVED] Scripting Command Run & Variabless

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

[SOLVED] Scripting Command Run & Variabless

Post by Enternal »

I noticed that:
run "<xypath>\Rar.exe" a Data Data;
works fine but if I use:
run '"<xypath>\Rar.exe" a Data Data';
as shown in a similar example in the Help, XYplorer would not be able to find Rar.exe.

It became quite clear when I was initially using 7za.exe and needed it to zip the Data folder to zip format with:
run "<xypath>\7za.exe" a -tzip Data Data;
and it would not work yet I cannot add ' either since it would not be able to find 7za.exe.

It seems that if the variable is nested between " and ', it the variables will become literal so instead of <xypath> = C:\Users\SomePath, it will become exactly <xypath>.
Last edited by Enternal on 16 Apr 2013 02:27, edited 1 time in total.

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Scripting Command Run & Variabless

Post by highend »

run """<xypath>\Rar.exe"" a Data Data";
One of my scripts helped you out? Please donate via Paypal

Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

Re: Scripting Command Run & Variabless

Post by Enternal »

What?!?! How did that work? Why does that work? That's very interesting! Thank you!

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Scripting Command Run & Variabless

Post by PeterH »

Enternal wrote:What?!?! How did that work? Why does that work? That's very interesting! Thank you!
In your 2nd example
run '"<xypath>\Rar.exe" a Data Data';
the whole parameter string
"<xypath>\Rar.exe" a Data Data
is single-quoted, i.e. taken as it is. And so <xypath> is not substituted by it's value.

admin
Site Admin
Posts: 67282
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting Command Run & Variabless

Post by admin »

compare:

Code: Select all

$a = 3; echo $a;

Code: Select all

$a = 3; echo '$a';

Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

Re: Scripting Command Run & Variabless

Post by Enternal »

Thank you! I learned something new! So the single quote pretty much makes it take what inside of it as it is.

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Scripting Command Run & Variabless

Post by j_c_hallgren »

Enternal wrote:Thank you! I learned something new! So the single quote pretty much makes it take what inside of it as it is.
Even though I'm not a script writer, I've seen literally dozens of posts here that were related to use or misuse of quotes and/or dbl quotes...it's probably one of the more important things to learn about XY scripts, it seems.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Scripting Command Run & Variabless

Post by PeterH »

One problem is the different meaning of single and double quotes.

But what should I say: it makes sense this way. But you must understand it :biggrin:

Another problem is the ability to often define strings *without* using quotes. If it works people often tend to learn "it's allowed" - and don't understand when in some cases it doesn't work. So please always avoid specifying strings without quotes!
(This is getting more problematic as there are still examples in help where quotes are missing :cry: )
(Though I understand it's hard to correct them :( )

Generally it would be helpful if XY would at least give some info/warning if a script omits quotes when neccessary - but I think the parser (or how you call it) isn't made for this.

And very best: always try to code as good as possible :ugeek:

admin
Site Admin
Posts: 67282
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting Command Run & Variabless

Post by admin »

PeterH wrote:One problem is the different meaning of single and double quotes.
Note that I did not invent this. Like many other feeatures of XY scripting it's taken from PHP syntax.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Scripting Command Run & Variabless

Post by PeterH »

admin wrote:
PeterH wrote:One problem is the different meaning of single and double quotes.
Note that I did not invent this. Like many other feeatures of XY scripting it's taken from PHP syntax.
I remember that when you explained the different usage of single and double quotes the first time, some years ago, I said I don't like it.
One reason: I was used that both are identical. :biggrin:
(And I was used to see syntax errors when a string was not quoted 8) )

Now I have used the different meaning of quotes for some time, and it's right: it has some advantages: as variables are allowed in double quoted strings you save a lot of starting/ending quotes and concatenation. Quite useful!

But if I need double quotes as characters, I must include them in single quotes - and lose the ability to include variables.
Or must use double quoted strings and double the included double quotes. (What a fine sentence :P )

OK: each system has advantages and disadvantages :mrgreen:

Now saying I've learned to live with the way it works: I had to learn that! And always keep it in mind. While some people doing scripting just want to quickly achive some result, but not look for such silly differences. I'm afraid for those it's not the best solution that they must look for quoting, and even differentiate between single and double quotes.

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Scripting Command Run & Variabless

Post by highend »

But if I need double quotes as characters, I must include them in single quotes - and lose the ability to include variables.
Or must use double quoted strings and double the included double quotes. (What a fine sentence )
Or:

Code: Select all

$qm = chr(34);
 $item = "<curitem>";
 text "$qm$item$qm";
Ofc this is only useful, if you work with variables...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 67282
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting Command Run & Variabless

Post by admin »

There is also a function quote().

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Scripting Command Run & Variabless

Post by PeterH »

highend wrote:
But if I need double quotes as characters, I must include them in single quotes - and lose the ability to include variables.
Or must use double quoted strings and double the included double quotes. (What a fine sentence )
Or:

Code: Select all

$qm = chr(34);
 $item = "<curitem>";
 text "$qm$item$qm";
Ofc this is only useful, if you work with variables...
Please see what I say now just as your example: as further examples. Doesn't really say what's good or bad or so...

In the following code each line in a group is identical. (I hope...)

Code: Select all

 $qm = chr(34);
 $qm = """";
 $qm = '"';

 $item = "<curitem>";
 $item = <curitem>;

 text "$qm$item$qm";
 text '"'.$item.'"';
 text """$item""";
(The very last line, and a bit the 2nd are just what you wanted *not* to show :-) )

And sure: there is quote(). Not bad in this situation - but bad if this quoted expression is only part of the result: a function cannot be inside a quoted string, and as such has to be concatenated:

Code: Select all

 text "item = ".quote($item).".";
 text "item = ""$item""."
But as I mostly use double quoted strings I decided to generally use single quotes to qualify texts:

Code: Select all

 text "item = '$item'."
(Double quotes are more eye-catching - but here I prefer the simpler coding :-) )

Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

Re: Scripting Command Run & Variabless

Post by Enternal »

Lol! Looks like my bug report on quotes (actually due to my misuse and understanding of the double vs single quotes) have led to quite an interesting conversation about quotes! And... wow am I lost. I'm so used to single quotes and double quotes being the same as well and it turns out quite different than I have expected.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Scripting Command Run & Variabless

Post by PeterH »

Enternal wrote:Lol! Looks like my bug report on quotes (actually due to my misuse and understanding of the double vs single quotes) have led to quite an interesting conversation about quotes! And... wow am I lost. I'm so used to single quotes and double quotes being the same as well and it turns out quite different than I have expected.
Fine: then it was worth the words :D

Post Reply