(Self-answered) Run bash script with % (percent) symbol in arguments (error "The system cannot find the file specified")

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
hsandt
Posts: 5
Joined: 16 May 2025 19:24

(Self-answered) Run bash script with % (percent) symbol in arguments (error "The system cannot find the file specified")

Post by hsandt »

Problem

I tried to run a bash script to convert my image and rescale it, passing a scale with % (percent) symbol, but it failed. I put the script on a custom button (Toolbar > Customize Toolbar…) but that could also be done with a custom contextual menu (Tools > Configuration… (F9) > General > Custom Event Actions).

My script looks like this (note: I entered button action without final semicolon ; but it's automatically added in the end):

Code: Select all

run bash "path\to\scripts\convert_image.sh" jpg webp -s 50%
However it will fail with:
The system cannot find the file specified.
XYplorer 2026-10-13 percent error The system cannot find the file specified - private.png
Attempts

I tried to escape the % with double percent %%, but to no avail.

Solution

EDIT 2026-11-01, XYplorer XYplorer 27.00.0100: the old solution wasn't working, this is the correct one:

Surround hyphenated options with single or double quotes:

Code: Select all

run bash "path\to\scripts\convert_image.sh" jpg webp "-s" 50%
---

OLD solution (didn't work when tried again on 2026-11-01, XYplorer 27.00.0100):

Following other scripts I found online, I surrounded the bash command with single quotes:

Code: Select all

run bash '"path\to\scripts\convert_image.sh" jpg webp -s 50%'
and it worked.
To see the attached files, you need to log into the forum.
Last edited by hsandt on 01 Nov 2026 12:28, edited 1 time in total.

WirlyWirly
Posts: 332
Joined: 21 Oct 2020 23:33
Location: XY 64-Bit | Win 11 @ 100% (3440x1440)

Re: (Self-answered) Run bash script with % (percent) symbol in arguments (error "The system cannot find the file specifi

Post by WirlyWirly »

Check out the lax() function in the help file, which will "relax" the quotation requirements.

I use it pretty much every time I call the run command, it's great 🥳

Also, out of curiosity, are you running XY in wine, or are you like me and using something like gitbash\wsl to run shell scripts?

hsandt
Posts: 5
Joined: 16 May 2025 19:24

Re: (Self-answered) Run bash script with % (percent) symbol in arguments (error "The system cannot find the file specifi

Post by hsandt »

WirlyWirly wrote: ↑30 Oct 2026 13:02 Check out the lax() function in the help file, which will "relax" the quotation requirements.

I use it pretty much every time I call the run command, it's great 🥳

Also, out of curiosity, are you running XY in wine, or are you like me and using something like gitbash\wsl to run shell scripts?
I'm using gitbash, although it's a normal terminal window that opens (in a flash) when I run the script in XYplorer (but I know can run "bash" from it manually and it switches to MINGW64 bash).

Urg, I just tried my single quote trick today and my script stopped working... (it opens the terminal for a flash, but nothing happens, unlike when not passing -s scale option)

I tried lax in different ways:

Code: Select all

run lax(bash '"path\to\scripts\convert_image.sh" jpg webp -s 50%')
run bash lax('"path\to\scripts\convert_image.sh" jpg webp -s 50%')
run bash lax("path\to\scripts\convert_image.sh" jpg webp -s 50%)
etc., but the script still did nothing (with error message this time)

With more tests I found that the hyphen in option "-s" was the culprit. I just had to surround that one with single or double quotes. The percentage argument was OK (I tried with "-s x1080" to test and it still failed, hinting me that hyphen was the culprit).

So this works:

Code: Select all

run bash "path\to\scripts\convert_image.sh" jpg webp "-s" 50%
and I have no idea why my single quotes hack around *everything* worked before.

Also, it looks like even lax() can't handle the hyphen. I managed to make it work after quoting the hyphen:

Code: Select all

run lax(bash "path\to\scripts\convert_image.sh" jpg webp "-s" 50%)
but lax doesn't play any extra role at this point since it already worked without it.

I will edit my OP so people can find the solution faster.

WirlyWirly
Posts: 332
Joined: 21 Oct 2020 23:33
Location: XY 64-Bit | Win 11 @ 100% (3440x1440)

Re: (Self-answered) Run bash script with % (percent) symbol in arguments (error "The system cannot find the file specifi

Post by WirlyWirly »

Not entirely unrelated, but I see from your script name that it is an image converter.

I recently shared one of my XYScript that uses the ImageMagick binary to quickly convert the selected list items into other formats. The script includes various presets for avif, jxl, webp, and png, but the pattern is easily replicated for other formats\options.

Thought you might find it useful, if you'd like to try a native XYScript to do probably the same thing as your shell script...

https://www.xyplorer.com/xyfc/viewtopic ... 62#p240362

Post Reply