Nautilus-scripts don't handle blanks in filenames properly

Bug #95519 reported by Stefan Wagner
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Nautilus
New
Low
nautilus (Ubuntu)
Triaged
Low
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
files=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

for file in $files
do
 zenity --info --text "$(md5sum $file)"
done
# ---- 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 $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
echo "-----------"

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

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

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

Revision history for this message
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: http://bugzilla.gnome.org/show_bug.cgi?id=424606

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

Content of $HOME/.gnome2/nautilus-scripts/expose
#!/bin/tcsh
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_SELECTED_FILE_PATHS" >> $report
echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS >> $report
echo "NAUTILUS_SCRIPT_SELECTED_URIS" >> $report
echo $NAUTILUS_SCRIPT_SELECTED_URIS >> $report
echo "NAUTILUS_SCRIPT_WINDOW_GEOMETRY" >> $report
echo "$NAUTILUS_SCRIPT_WINDOW_GEOMETRY" >> $report
echo "NAUTILUS_SCRIPT_CURRENT_URI" >> $report
echo "$NAUTILUS_SCRIPT_CURRENT_URI -- " >> $report

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

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
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
/home/doug/ScratchPad /home/doug/space2 space2 /home/doug/space space
NAUTILUS_SCRIPT_SELECTED_URIS
file:///home/doug/ScratchPad file:///home/doug/space2%20%20space2 file:///home/doug/space%20space
NAUTILUS_SCRIPT_WINDOW_GEOMETRY
847x753+767+72
NAUTILUS_SCRIPT_CURRENT_URI

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.

Revision history for this message
Sebastien Bacher (seb128) wrote :

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

Changed in nautilus:
status: Confirmed → Triaged
Revision history for this message
Stefan Wagner (wagner-stefan) wrote :

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

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

Revision history for this message
Leolik (leolikua) wrote :

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

Revision history for this message
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

Revision history for this message
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).

#!/bin/bash
IFS=$'\n'
for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
 zenity --info --text "$(md5sum $file)"
done

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:
#!/bin/bash
IFS=$'\n'
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/')

-Reece

Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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