LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-04-2018, 04:15 PM   #1
winger9
Member
 
Registered: Jan 2014
Posts: 85

Rep: Reputation: 1
Why does Kate replace spaces in filename with "%20", thus preventing opening it?


I'm using the the Kate editor ver 16.04.2 on live knoppix 7.7.1 on a usb stick.

When I double-click on a normal text file in pcmanfm, Kate opens but it
replaces the spaces in the filename with "%20", and a message says "New", which
I presume means "new file". The contents of the file I double-clicked on do not
appear in Kate, but the text window is empty.

Say the true filename is "my notes", then Kate changes it to "my%20notes".

If I open Kate separately, then opening the file in the following ways DOES
work:
a) Using File/Open from Kate's menu, and selecting the file from there.
b) Clicking and dragging the file from pcmanfm across to the Kate window.

My humble question:
Why does the double-click opening method replace spaces with "%20", and how do
I fix it?

On my main Debian system on the hard drive, Kate (ver 3.8.4) opens a
double-clicked file fine.
 
Old 06-04-2018, 04:57 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,141
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
Quote:
Why does the double-click opening method replace spaces with "%20", and how do I fix it?
You should not have files names with spaces in them. Change my file to my_file or something with allowed characters. If your file name has spaces in it then you'll have to quote the name. Or better yet, don't put spaces in file names.

If you try
Code:
ls my notes
You'll get an error
Code:
ls "my notes"
Will work.
 
Old 06-05-2018, 12:19 AM   #3
jbuckley2004
Member
 
Registered: Aug 2004
Distribution: Fedora (KDE spin)
Posts: 224

Rep: Reputation: 70
I'm not sure teckk is exactly right. %20 is the hexadecimal equivalent to the space character. Spaces in file names have been "ok" to use in both linux and windows (and I think in whatever version of the OS Apple's been using) for quite some time. There are some rules, though.

If your using a terminal emulator (I use KDE, and Konsole alot) it will take spaces for the names of files, but you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character (the space, in this case, which usually means "here is the next part of the command on this line") and take it as a plain character. So the command to list my file.txt should be typed as
Code:
#ls my\ file.txt
No quotes needed, but it often becomes hard to read.

But here's something I discovered about kate. I often create playlists for my mp3 player using VLC. The standard play list has two lines for every file, the first being a comment, the second being the file name. When I use kate to open the file created by VLC, the file name line always uses %20 for spaces, but the comment line does not. That one reads as you'd expect, with the space character.

I usually do a edit -> replace all in kate to change the %20s to the space character.

If I recall correctly, kwrite does not do this. So yes, I agree that it's some setting or other in kate that I do not understand either.
 
1 members found this post helpful.
Old 06-05-2018, 12:24 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Just a note that the OP, presumably, has also set up a question on the issue on Stack Exchange:

https://unix.stackexchange.com/quest...ing-opening-it
 
Old 06-05-2018, 11:23 AM   #5
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,142

Rep: Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314
Quote:
Originally Posted by jbuckley2004 View Post
Spaces in file names have been "ok" to use in both linux … for quite some time. If your using a terminal emulator … you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character
Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots
 
Old 06-05-2018, 11:27 AM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by DavidMcCann View Post
Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots
It may be recommended that you don't use them, but spaces *are* allowed in *nix filenames.

https://unix.stackexchange.com/quest...-in-a-filename
 
Old 06-05-2018, 02:55 PM   #7
winger9
Member
 
Registered: Jan 2014
Posts: 85

Original Poster
Rep: Reputation: 1
Thanks for your kind responses.

Could I humbly point out that it's not the use of spaces in filenames that is
the problem.


As I mentioned at the end of my original thread, I have NO PROBLEM
double-clicking a filename in pcmanfm* file manager on my main Debian system on
the hard drive. Kate happily opens the file, and spaces aren't replaced with
%20. (*I think it's an older version than pcmanfm on the live knoppix 7.7.1 on
usb stick.)

It's when I double-click a file in pcmanfm (ver 1.2.4) ON THE STICK when spaces
are replaced by %20 in Kate.

I did the following tests (SOLELY on the stick):

1) Using pcmanfm:

a) (This is the SAME scenario I've already described in my original thread.)

Kate was already the default application that's launched when a text file is
double-clicked. I double-clicked the file "my notes" in pcmanfm, but Kate
opened a NEW file called "my%20notes", with nothing in it.

b) While Kate was still open at "a)", I did the following to see what filename
was passed to Kate:

Code:
$ ps ax | grep kate
4893 tty5     Sl     0:01 kate -b file:///home/knoppix/my%20notes
c) I changed the default launch application from Kate to KWrite. When I
double-clicked "my notes", KWrite opened a NEW file called "my%20notes".

d) I changed the default launch application to Leafpad. When I double-clicked
"my notes", Leafpad CORRECTLY opened "my notes".

2) Using nautilus file manager:

I set the default launch application to Kate. When I double-clicked "my notes",
Kate CORRECTLY opened "my notes" (ie no %20 used).

CONCLUSIONS so far:

It seems to be ONLY pcmanfm (not other file managers, such as nautilus) that
"causes" %20 to be used in Kate. Also it seems to be KDE launch applications
(Kate and KWrite) in which the %20 problem occurs - but only via pcmanfm. I
don't think pcmanfm itself is a KDE application.

HOWEVER, I still don't know what the cure is.
 
Old 06-06-2018, 10:34 AM   #8
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,142

Rep: Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314
I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.

@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?
 
Old 06-06-2018, 11:36 AM   #9
Timothy Miller
Moderator
 
Registered: Feb 2003
Location: Arizona, USA
Distribution: Debian, EndeavourOS, OpenSUSE, KDE Neon
Posts: 4,005
Blog Entries: 26

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
Quote:
Originally Posted by DavidMcCann View Post
I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.

@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?

I'm betting this is correct. %20 is the url code for a space, so passing the directory as a URL not as a straight directory would definitely cause this behavior.
 
Old 06-08-2018, 02:36 PM   #10
winger9
Member
 
Registered: Jan 2014
Posts: 85

Original Poster
Rep: Reputation: 1
Solved!

I've found the cure!

I'm using the LXDE desktop environment, and did the following to fix the
problem.

Select the KMenu icon at the left end of the Desktop Panel at the bottom of the
screen. Select Accessories/MainMenu. When the MainMenu application appears,
click on Accessories in the left box, then click on Kate in the middle box, then
click on Properties at the right.

In the "Command" box, replace "kate -b %U" with "kate -b".

When I now double-click a text file in pcmanfm, Kate correctly opens the file,
ie spaces aren't replaced with %20.

I don't have much knowlegde of the percent parameters (like %U), but I've a
feeling that %U might mean "Treat the argument supplied to Kate as a URL" (not
as a normal file).

Thanks very much for the help that you've all given.

Last edited by winger9; 06-08-2018 at 03:21 PM. Reason: Removed unneeded paragraph.
 
Old 06-08-2018, 04:26 PM   #11
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Nice one!

Here is a list of the parameter options recommended in the freedesktop.org standard (half-way down the page).

https://standards.freedesktop.org/de...ec-latest.html

You will notice that %U allows multiple files to be passed to the target application (e.g. you could highlight several files and then open them all in Kate). So, a better bet might be to replace the %U by %F.

Try this out and let us know how it goes.
 
  


Reply

Tags
kate



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wget "cannot write to"/ "filename too long" problem sybrenkooistra Linux - Newbie 6 09-03-2012 09:53 PM
unable to replace "ö" to "p" in shell scripting with "sed" meninmech Programming 5 06-22-2012 02:58 PM
[SOLVED] "tail -n 1 filename" error while "head -n 1 filename" is ok? type8code0 Linux - Newbie 3 03-21-2011 06:10 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration