Nautilus-scripts don't handle blanks in filenames properly

Bug #95519 reported by Stefan Wagner on 2007-03-24
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nautilus (Ubuntu)
Ubuntu Desktop Bugs

Bug Description

Binary package hint: nautilus

Nautilus-scripts don't handle blanks in filenames properly.

Reproduce the bug:
a) Create some files with blanks:

echo aaa > ~/tmp/foo\ bar
echo aaa > ~/tmp/bar\ foo

b) Create a script to operate on files:
# ---- start of script

for file in $files
 zenity --info --text "$(md5sum $file)"
# ---- end of script

Create that script in ~/.gnome2/nautilus-scripts.
Make it executable.
It will shine up in the context-menu of nautilus to run scripts.

It will execute fine, if you mark a few files, which don't contain a blank.
If there is a blank, it doesn't work.

To see how this is happening, create another script:
echo "---files---"
echo "-----------"

You'll get something like:
    /home/stefan/tmp/foo bar /home/stefan/tmp/foo foo

instead of:
    /home/stefan/tmp/foo bar
    /home/stefan/tmp/foo foo

Suggestion: Use a different delimiter to split multiple marked files.
Use '\n' instead of ' '.

Sebastien Bacher (seb128) wrote :

Thanks for your bug report. This bug has been reported to the developers of the software. You can track it and make comments here:

Changed in nautilus:
assignee: nobody → desktop-bugs
importance: Undecided → Low
status: Unconfirmed → Confirmed
Changed in nautilus:
status: Unknown → Unconfirmed
Doug McNutt (dmcnutt) wrote :

Content of $HOME/.gnome2/nautilus-scripts/expose
set report = $HOME/expose.txt
echo >> $report
date >> $report
echo "Arg1 is $1" >> $report
echo "Arg2 is $2" >> $report
echo "Arg3 is $3" >> $report
echo "$NAUTILUS_SCRIPT_CURRENT_URI -- " >> $report

I have selected three files in my home directory
space\ space
space2\ \ space2

This is the result of choosing scripts_expose with the right mouse button:

Sat May 3 19:56:56 MDT 2008
Arg1 is ScratchPad
Arg2 is space2 space2
Arg3 is space space
/home/doug/ScratchPad /home/doug/space2 space2 /home/doug/space space
file:///home/doug/ScratchPad file:///home/doug/space2%20%20space2 file:///home/doug/space%20space

Note that the arguments are correct.
Note that the selected URI's properly show the URL-encoded double space in the file name.
Note that the file paths have truncated the double space into a single space.

The only document I have is "Ubuntu Hacks", O'Reilly, June 2006 which clearly says the files and URIs are new-line delimited in Hack 24.
It appears that the current rule is to use a double space.

Sebastien Bacher (seb128) wrote :

could you try if that's still an issue in hardy?

Changed in nautilus:
status: Confirmed → Triaged
Stefan Wagner (wagner-stefan) wrote :

I'm using xfce/xubuntu with Thunar - well - with midnight commander, to ... -
Yes, nautilus is installed.

Creating the script, moving it to place, testing: Still failing with "file x" but working else.

Leolik (leolikua) wrote :

this bug - still reproduce in hardy ((
please fix this bug

Sebastien Bacher (seb128) wrote :

the code is opensource you can work yourself on the required changes if you really need those, there is just too many bugs to work on everything and this one is not a high priority one for most users

Reece (reece) wrote :

One way to solve your problem is to set IFS to explicitly cause files to be split on newlines, as below. For an explanation of how this works, see the bash man page. Similar functionality exists in sh and zsh (and probably the csh-derived shells as well).

 zenity --info --text "$(md5sum $file)"

Although quoting in shell scripts is frustrating and obtuse, the behavior you experienced is not a bug. I recommend closing as not-a-bug.

The only misfeature here is that \n is technically legal in filenames; \0 would have been preferable.

I can't resist. Here's a great way to impress people at dinner parties and wow chicks:
zenity --list --column md5 --column file $(find ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS} -type f -print0 | xargs -0r md5sum | perl -pe 's/^(\S+)\s\s/$1\n/')


harm (harm-meijer) wrote :

Sorry for digging up an old thread here but I see this as a bug.
Reece has a point there, the paths are seporated by new line not a good idea if that's a valid character for directory or file name. If this is "fixed" with the \0 seporator than all scripts depending on \n would be broken.

if Doug would echo the variable with the -e option it would come out ok.

I had made a script checking the variable but just dumped env (env > ~/myvars.txt)

Just posted here to get an email update so I know when and if this is fixed to update my scripts.

By the way I am using jaunty (or mint 8) Nautilus 2.28.1

Changed in nautilus:
importance: Unknown → Low
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.