LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-29-2015, 05:36 PM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
Why does auto-complete in bash think a pdf file is a directory???


I do not recall when I discovered auto-complete in bash but it is now embedded in the muscle memory of my fingers That said, I have recently come across a rather strange behavior. bash starts with /home/ken as the working directory. The contents of the directory are as follows
Code:
[ken@taylor12 ~]$ ll

-rw-rw-r--. 1 ken ken   2824 Mar  9  2014 David Ford re. Keith Branch
-rw-r-----. 1 ken ken 521208 Oct 26 09:21 Declaration Pages.pdf
drwxr-xr-x. 2 ken ken  20480 Nov 29 15:22 Desktop
drwxr-xr-x. 2 ken ken   4096 Nov 25 11:45 Documents
drwxr-xr-x. 2 ken ken   4096 Nov 27 18:47 Downloads
drwxr-xr-x. 2 ken ken   4096 Oct 15 06:23 dwhelper
drwxr-xr-x. 2 ken ken   4096 Jun 25  2010 Enigmail Keys
-rw-rw-r--. 1 ken ken    857 Jun 28  2012 FOXUSER.DBF
-rw-rw-r--. 1 ken ken   4608 Jun 28  2012 FOXUSER.FPT
drwxr-xr-x. 2 ken ken   4096 Jun 24  2012 icons
drwxr-xr-x. 2 ken ken   4096 Jun 21  2012 Music
-rw-rw-r--. 1 ken ken 105691 May 19  2015 NCPUC Complaint.pdf
drwxr-xr-x. 2 ken ken   4096 Nov 29 08:17 pdf
drwxrwxr-x. 3 ken ken   4096 Sep 22 09:02 Pictures
-rw-rw-r--. 1 ken ken    851 Aug  3 08:00 Pills
drwxr-xr-x. 2 ken ken   4096 Jun 21  2012 Public
drwxr-x---. 2 ken ken   4096 Nov  2 13:49 scan
-rw-rw-r--. 1 ken ken     56 Sep 29 09:42 Scholarship Recipients
If I enter De[tab] I would expect Desktop to be the only matching directory. However, I see
Code:
[ken@taylor12 ~]$ cd De
Declaration Pages.pdf  Desktop/               
[ken@taylor12 ~]$ cd De
Declaration Pages.pdf is NOT a directory and cd will of course not change into it. A little experimenting... cd Sc[tab] produced
Code:
[ken@taylor12 ~]$ cd Scholarship\ Recipients 
bash: cd: Scholarship Recipients: Not a directory
[ken@taylor12 ~]$
In fact, any file name with an embedded space seems to be interpreted as a candidate for being a directory. Is this to me expected or have I uncovered a bug?

TIA,

Ken
 
Old 11-29-2015, 06:16 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
AFAIK, tab complete is just a string search on all 'files' in the dir, regardless of their 'type' ie the first char in the long listing.
Remember that in *nix, (almost) everything is treated as a file - sort of.
https://en.wikipedia.org/wiki/Everything_is_a_file
 
1 members found this post helpful.
Old 11-29-2015, 06:37 PM   #3
Aia
Member
 
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
Quote:
Originally Posted by taylorkh View Post
[...]
In fact, any file name with an embedded space seems to be interpreted as a candidate for being a directory. Is this to me expected or have I uncovered a bug?

TIA,

Ken
It is not a bug, it is the expected behavior. The built-in cd command is not playing any role there. The shell is giving you clues. If you were to enter cd space tab tab, the shell will display all the files available for choosing in the current directory. Heck, you can even enter a non-existent command, like: nono space tab tab and still, the shell will give you a hint of what's available in the directory.
 
1 members found this post helpful.
Old 11-29-2015, 06:37 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by chrism01 View Post
AFAIK, tab complete is just a string search on all 'files' in the dir, regardless of their 'type' ie the first char in the long listing.
Remember that in *nix, (almost) everything is treated as a file - sort of.
https://en.wikipedia.org/wiki/Everything_is_a_file
The shell is smart enough, normally, to understand the context. For example, ./pro<TAB><TAB> will expand to ./program only if ./program is executable. Same for cd:
Code:
$ ls
bind       Desktop    Downloads   Pictures      rp        Templates
daapd.log  dhcp       index.html  Public        rp.c      Videos
daapdump   Documents  Music       python_games  smb.conf
$ cd d<TAB><TAB>
expands to dhcp/dhclient-e. Just tested on my trusted Raspberry Pi.

Sorry I have no answer for the OP. Perhaps one of the 100000 config settings of the shell changes its behaviour?

EDIT: The relevant part of the bash reference manual is http://www.gnu.org/software/bash/man...ble-Completion, perhaps some wisdom can be found there.

Last edited by berndbausch; 11-29-2015 at 06:41 PM.
 
1 members found this post helpful.
Old 11-29-2015, 07:42 PM   #5
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks folks! I guess I was expecting to much of cd or the shell. I understand the error of my train of thought. I will dispose of the offending file "Declaration Pages.pdf" I only noticed the cd Desktop issue after I had created this temporary file as the result of scanning some insurance documents so that I could email them.

Regards,

Ken
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] lp doesn't print file to pdf directory after installing cups-pdf using synaptic mrcj Debian 1 10-09-2013 07:18 PM
Bash auto-complete of environment variables armandino101 Linux - General 11 12-20-2012 05:22 AM
How to get tab auto complete in bash to scroll through all possible choices joeldick Linux - Software 5 04-06-2011 04:27 PM
Does there a software which read RNG format to auto complete tags in XML file? nadavvin Linux - Software 0 11-02-2006 12:49 PM
bash auto-complete behaviour changes acid_kewpie Linux - Software 5 10-26-2002 01:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:47 PM.

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