[SOLVED] Scripting Command Run & Variabless
Forum rules
You might want to read this if you're looking for priority service
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%).
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.
How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
You might want to read this if you're looking for priority service
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%).
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.
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
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>.
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
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
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
In your 2nd exampleEnternal wrote:What?!?! How did that work? Why does that work? That's very interesting! Thank you!
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
compare:
Code: Select all
$a = 3; echo $a;Code: Select all
$a = 3; echo '$a';FAQ | XY News RSS | XY X
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: Scripting Command Run & Variabless
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
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.Enternal wrote:Thank you! I learned something new! So the single quote pretty much makes it take what inside of it as it is.
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.
(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
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
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
)
(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
But what should I say: it makes sense this way. But you must understand it
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
(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
-
admin
- Site Admin
- Posts: 67282
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Scripting Command Run & Variabless
Note that I did not invent this. Like many other feeatures of XY scripting it's taken from PHP syntax.PeterH wrote:One problem is the different meaning of single and double quotes.
FAQ | XY News RSS | XY X
-
PeterH
- Posts: 2830
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Scripting Command Run & Variabless
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.admin wrote:Note that I did not invent this. Like many other feeatures of XY scripting it's taken from PHP syntax.PeterH wrote:One problem is the different meaning of single and double quotes.
One reason: I was used that both are identical.
(And I was used to see syntax errors when a string was not quoted
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
OK: each system has advantages and disadvantages
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
Or: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 )
Code: Select all
$qm = chr(34);
$item = "<curitem>";
text "$qm$item$qm";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:
-
PeterH
- Posts: 2830
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Scripting Command Run & Variabless
Please see what I say now just as your example: as further examples. Doesn't really say what's good or bad or so...highend wrote:Or: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 )Ofc this is only useful, if you work with variables...Code: Select all
$qm = chr(34); $item = "<curitem>"; text "$qm$item$qm";
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""";
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""."
Code: Select all
text "item = '$item'."
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: Scripting Command Run & Variabless
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
Fine: then it was worth the wordsEnternal 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.
XYplorer Beta Club