Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nemo actions miss space with multiple spaces in one file name #3527

Open
catscarlet opened this issue Feb 11, 2025 · 5 comments
Open

Nemo actions miss space with multiple spaces in one file name #3527

catscarlet opened this issue Feb 11, 2025 · 5 comments

Comments

@catscarlet
Copy link

Distribution

Mint 20.3

Package version

nemo 5.2.4

Frequency

Always

Bug description

here is my action file

[Nemo Action]
Active=true
Name=waifu2x anime script
Comment=This is a test for Nemo actions.  Action will be applied to %N
Exec=/home/cat/Documents/app/script.sh %F
Icon-Name=clementine
Selection=S
Extensions=any
Quote=double
Terminal=true

here is the related file

cat@cat-B85M-D3H:/media/cat/Temp/Output/Shotcut/ai-story/image/retired$ ll
total 37349
drwxrwxrwx 1 cat cat      512 2月  12 00:56  ./
drwxrwxrwx 1 cat cat      184 2月  12 00:27  ../
-rwxrwxrwx 1 cat cat 11675478 2月  12 00:53  22_2x.png*
-rwxrwxrwx 1 cat cat  3879057 2月  12 00:28 '2    2.png'*

here is my script.sh

#!/usr/bin/env bash

echo '$1: '$1

So you can see there is a filename '2 2.png' which contains more than one space.

When it is called. The %F past to my script, but my script received $1: /media/cat/Temp/Output/Shotcut/ai-story/image/retired/2 2.png only one space.

I'm still using LinuxMint 20.3 Cinnamon. If this is fixed in LinuxMint, please tell me. If not ...... well that's a bug to nemo.

Steps to reproduce

Try nemo actions on one file with multiple spaces

Expected behavior

it should pass %F as the full filepath

Additional information

I seached and saw nobody talked about this

@Jeremy7701
Copy link
Contributor

Jeremy7701 commented Feb 11, 2025

It's your script.
Try echo '$1:' "$1"
bash is removing excess spaces.

echo 2 2.png displays 2 2.png
echo "2 2.png" displays 2 2.png

Note that the trailing * appears to be silently ignored from the filename.
This could cause problems, in the future perhaps?

@catscarlet
Copy link
Author

Thanks @Jeremy7701

So I do need help.
Here is all of my script. I change the echo $1 to echo '$1:' "$1" so it works now but I have trouble using it.

#!/usr/bin/env bash

echo '$1: ' "$1"

inputfile="$1"
echo '$inputfile: ' "$inputfile"

filefullname=$(basename -- "$inputfile")
filedirname=$(dirname -- "$inputfile")
extension="${filefullname##*.}"
filename="${filefullname%.*}"
newname="${filename}_2x.${extension}"

echo 'filefullname: '${filefullname}
echo 'filename: '${filename}
echo 'filedirname: '${filedirname}
echo 'extension: '${extension}
echo 'newname: '${newname}
#echo `pwd`

target=${filedirname}/${filename}_2x.${extension}
echo 'target: '${target}
#echo "$waifu2x_cmd -i ${filefullname} -v -m /media/cat/SATA3-100G-3T/test/waifu2x-ncnn-vulkan-20210521-ubuntu/models-upconv_7_anime_style_art_rgb -o ${filename}_2x.${extension}"

waifu2x_cmd="/mystorage2/tools/waifu2x-ncnn-vulkan-20220728-ubuntu/waifu2x-ncnn-vulkan"

if [[ -x "${waifu2x_cmd}" ]]
then
    echo "File '${waifu2x_cmd}' is executable"
else
    echo "File '${waifu2x_cmd}' is not executable or found"
fi


testcmd="file \"$inputfile\""
echo $testcmd
eval ${testcmd}


fullcmd="$waifu2x_cmd -i \"$inputfile\" -v -m /mystorage2/tools/waifu2x-ncnn-vulkan-20220728-ubuntu/models-upconv_7_anime_style_art_rgb -o \"${target}\""

echo ${fullcmd}

eval ${fullcmd}

read -n1 -s -r -p $'Press any key to continue...\n' key


Both the filefullname and the filedirname are broken and I don't know how to fix it.

Also about the trailing * I think that won't be a problem. This is a NTFS partition so every file has execute permission

@catscarlet
Copy link
Author

OK I figured it out.

Turns out that was not the basename line's mistake. It was echo.

So I modified most of the quote needed part.

#!/usr/bin/env bash

echo '$1: ' "$1"

inputfile="$1"
echo '$inputfile: ' "$inputfile"

filefullname=$(basename -- "$inputfile")
filedirname=$(dirname -- "$inputfile")
extension="${filefullname##*.}"
filename="${filefullname%.*}"
newname="${filename}_2x.${extension}"

echo 'filefullname: '"${filefullname}"
echo 'filename: '"${filename}"
echo 'filedirname: '"${filedirname}"
echo 'extension: '"${extension}"
echo 'newname: '"${newname}"

#echo `pwd`

target="${filedirname}/${filename}_2x.${extension}"
echo 'target: '"${target}"

waifu2x_cmd="/mystorage2/tools/waifu2x-ncnn-vulkan-20220728-ubuntu/waifu2x-ncnn-vulkan"

if [[ -x "${waifu2x_cmd}" ]]
then
    echo "File '${waifu2x_cmd}' is executable"
else
    echo "File '${waifu2x_cmd}' is not executable or found"
fi


testcmd="file \"$inputfile\""
echo "$testcmd"
eval "${testcmd}"


fullcmd="$waifu2x_cmd -i \"$inputfile\" -v -m /mystorage2/tools/waifu2x-ncnn-vulkan-20220728-ubuntu/models-upconv_7_anime_style_art_rgb -o \"${target}\""

echo "${fullcmd}"

eval "${fullcmd}"

read -n1 -s -r -p $'Press any key to continue...\n' key

I think it works now.

@Jeremy7701
Copy link
Contributor

You can add an option on the first line of the script -x to print commands and their arguments as they are executed.

Note that I just about manage to get by in bash, for difficult questions go to https://unix.stackexchange.com/

It tends to be more common to use command substitution - that's writing $(command) where instead you have relied on braces expansion ${expression}.
In two cases, though, the braces thing is necessary - (pattern matching)
extension="${filefullname##*.}"
filename="${filefullname%.*}"

Also, use of eval can be dangerous - you are telling bash to execute a variable as a command.
For example, what happens if you have folders with embedded spaces?

Just noticed:-

testcmd="file \"$inputfile\""
echo "$testcmd"
eval "${testcmd}"

Is this correct?

@catscarlet
Copy link
Author

@Jeremy7701 Thank you for your more information.


Well sadly stackexchange often close my question by duplicated meanwhile the related answer is actually not related. I kinda give up that.

The ${expression} is one answer from stackexchange too, when I didn't know how to run command in a script.
I did it much worse before eval "${testcmd}". I used only ${testcmd} instead and it had the "multiple spaces issue" too.

testcmd="file \"$inputfile\""
echo "$testcmd"
eval "${testcmd}"

This part was for testing if the double quotes fix multiple space issue and it worked. It has no other purpose so I will comment this part after this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants