Executing the following script from the Nautilus "Scripts" right-click menu option with a filename that contains a percent sign removes the percent sign and the next character from the filename. E.g., if the file is called uvw10%xyz, the script will print uvw10yz to the file abc.txt.

echo "$1" >> abc.txt

Any character, even a space, can follow the percent sign and the problem remains. And I realize it works from the terminal; that's not the question. The point is that it doesn't work when run as a Nautilus script.

What's going on here? How can I fix it?

Apparently, the correct filenames can be printed like this:

while read line; do
    [ "$line" ] && echo "$line"

But I would still like to know what's happening with the precent sign in the original code.


I think uvw10%xyz has %x in it. So its considered as specifier i guess, Although it works fine from terminal. Try the below code

echo $1 >> abc.txt

You can also try this:

filepath=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS then name=${filepath##*/} then name=${name% then } then printf %s "$name"> abc.txt
  • In what sense is it a "specifier"? I realize it works from the terminal; that's not the question. It doesn't matter what letter, or even a space, is after the %. Your first code snippet is useless since it compresses spaces. Your afterthought might be useful. I asked why it was happening, though. Does anyone have an answer that isn't a guess? Is it a bug?
    – CrazyApe84
    Sep 8 '17 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.