LinuxQuestions.org
Help answer threads with 0 replies.
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 01-11-2024, 03:55 PM   #1
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36
Blog Entries: 1

Rep: Reputation: 2
$variable broken with tab completion into \$variable


paths are fictionalized but accurate

in my .bashrc I have environment variables such as:
Code:
shortcut="/home/me/startdir/"
In Vi I can do the following and tab completion works perfectly.
Code:
:e $shortcut/
In bash when I press tab,
Code:
cd $shortcut/s
becomes
Code:
cd \$shortcut/subdir
and the slash added before $ breaks the command.

- Is there a way to prevent this?
- Is there a better way to approach faster navigation?

Thank you!

Last edited by disk_bearing; 01-12-2024 at 01:08 PM.
 
Old 01-11-2024, 04:49 PM   #2
metaed
Member
 
Registered: Apr 2022
Location: US
Distribution: Slackware64 15.0
Posts: 365

Rep: Reputation: 171Reputation: 171
Something like this?

https://superuser.com/questions/2168...ugh-out-cdpath

Basically you would put the shortcuts in CDPATH. But you also have to install a bash addon, bash-completion, which redefines cd and looks at CDPATH.

Caveat: I have not installed bash-completion to try this.

Last edited by metaed; 01-11-2024 at 04:51 PM.
 
Old 01-11-2024, 05:41 PM   #3
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Thanks! That looks interesting and also intimidating. I don't care what anyone says, cli is really hard!
 
Old 01-12-2024, 03:50 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
I think it is tab completion, not CDPATH.
I cannot reproduce your behavior on my system, $setup stays unchanged if tab completion is used.
My settings:
Code:
$ echo $BASH_VERSION
5.0.17(1)-release
$ set | grep -i complet
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:histappend:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
What are your settings?
Perhaps you have a buggy completion code in /etc/profile.d/*comp*.sh or your bash version has a bug.
 
1 members found this post helpful.
Old 01-12-2024, 04:54 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
by the way, it is an interesting question, you might want to take $ as it is ($ char) or as a beginning of a variable. How can bash decide which one do you mean? What to do if you have both $short and $shortcut variables (for example)? What to do if you have no such variable set or contains something "strange"? Do you think bash completion should check everything? How long will it take?
 
1 members found this post helpful.
Old 01-12-2024, 05:00 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
It does the usual expansion:
type \$ if you want a literal $
type $sh
and hit tab, then it will expand to the first hit $short, hit tab again and it will show the matches $short and $shortcut
type c
and hit tab, and it will expand to $shortcut
 
1 members found this post helpful.
Old 01-12-2024, 01:33 PM   #7
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Quote:
Originally Posted by MadeInGermany View Post
What are your settings?
That was really interesting, now I have to study "set" and how to edit it.

Quote:
Originally Posted by MadeInGermany View Post
Code:
$ echo $BASH_VERSION
5.0.17(1)-release
$ set | grep -i complet
BASHOPTS=checkwinsize:cmdhist:
complete_fullquote:expand_aliases:
extquote:force_fignore:globasciiranges:histappend:
hostcomplete:
interactive_comments:progcomp:promptvars:sourcepath
mine:

Code:
$ echo $BASH_VERSION
5.1.16(1)-release
$ set | grep -i complet
BASHOPTS=checkwinsize:cmdhist:
complete_fullquote:expand_aliases:
extglob:
extquote:force_fignore:globasciiranges:histappend:
interactive_comments:progcomp:promptvars:sourcepath
Yours has hostcomplete and mine has extglob.

Last edited by disk_bearing; 01-12-2024 at 01:36 PM.
 
Old 01-12-2024, 01:48 PM   #8
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Quote:
Originally Posted by MadeInGermany View Post
It does the usual expansion:
type \$ if you want a literal $
type $sh
and hit tab, then it will expand to the first hit $short, hit tab again and it will show the matches $short and $shortcut
type c
and hit tab, and it will expand to $shortcut
All of my custom variables start with $d and tab expansion works fine with the variables only, for example:

Code:
$ $d
<tab>
$dd   $ddd  $ddo  $din  $dl   $dn   $dp   $dt   $dyn  $dyp
The problem occurs when I want to tab complete subdirs:
Code:
$ cd $dn/
<tab>
$ cd \$dn/
I bet it has to do with "extglob" in my "set"; "globbing" has been suggested for other issues of mine in the past. I will attempt to remove that with caution.
 
Old 01-12-2024, 02:06 PM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
If I set extglob with
Code:
shopt -s extglob
no difference - it still works.

You can unset extglob with
Code:
shopt -u extglob
And what happens if you do
Code:
$ echo $dn/
<tab>
 
1 members found this post helpful.
Old 01-12-2024, 03:09 PM   #10
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
I should have added that this is kubuntu, but I'll be moving to something else soon.

with and without histcomplete or extglob, the behavior persists.

Code:
$ shopt -s extglob
$ echo $dn/
<enter>
/home/me/startdir/
$ echo $dn/
<tab>
$ echo \$dn/
<enter>
$dn/
$ shopt -u extglob
$ echo $dn/
<enter>
/home/me/startdir/
$ echo $dn/
<tab>
$ echo \$dn/
<enter>
$dn/
 
Old 01-13-2024, 05:29 AM   #11
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The command
Code:
complete
shows your tab completion setup.
In some distos it's very complex.
 
1 members found this post helpful.
Old 01-13-2024, 07:54 AM   #12
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Quote:
Originally Posted by MadeInGermany View Post
Code:
complete
shows your tab completion setup.
That's awesome!! I don't see anything that obviously matches my issue. Here's mine, please share yours if you don't mind. I can use it to practice diffing. I will also diff it with my next distro.

Code:
complete -F _longopt mv
complete -F _root_command gksudo
complete -F _command nice
complete -F _longopt tr
complete -F _longopt head
complete -F _service /etc/init.d/rsync
complete -F _service /etc/init.d/cryptdisks-early
complete -F _longopt sha256sum
complete -F _longopt uniq
complete -F _command else
complete -F _root_command gksu
complete -F _service /etc/init.d/unattended-upgrades
complete -F _service /etc/init.d/cups-browsed
complete -F _longopt ptx
complete -F _service /etc/init.d/avahi-daemon
complete -F _longopt mkfifo
complete -F _longopt tee
complete -F _known_hosts traceroute
complete -j -P '"%' -S '"' fg
complete -F _longopt who
complete -F _service /etc/init.d/acpid
complete -F _service /etc/init.d/x11-common
complete -F _longopt grep
complete -F _longopt objdump
complete -F _longopt less
complete -F _longopt sha1sum
complete -F _longopt cut
complete -F _longopt mknod
complete -F _command padsp
complete -F _service /etc/init.d/plymouth
complete -F _service /etc/init.d/console-setup.sh
complete -F _longopt bison
complete -F _command nohup
complete -F _longopt od
complete -a unalias
complete -F _service /etc/init.d/kmod
complete -u groups
complete -F _longopt texindex
complete -F _known_hosts telnet
complete -F _completion_loader -D
complete -F _command vsound
complete -F _service /etc/init.d/cups
complete -c which
complete -F _longopt m4
complete -F _longopt cp
complete -F _longopt base64
complete -F _longopt strip
complete -F _longopt split
complete -v readonly
complete -o nospace -F _cd cd
complete -F _known_hosts showmount
complete -F _longopt tac
complete -F _longopt fold
complete -F _known_hosts mtr
complete -F _known_hosts fping
complete -F _longopt env
complete -F _user_at_host finger
complete -c type
complete -o dirnames -o filenames -F _apport-unpack apport-unpack
complete -F _service /etc/init.d/apport
complete -F _known_hosts ssh-installkeys
complete -F _root_command kdesudo
complete -F _longopt expand
complete -F _longopt ln
complete -F _command aoss
complete -u w
complete -F _service /etc/init.d/kerneloops
complete -F _service /etc/init.d/alsa-utils
complete -F _service /etc/init.d/ufw
complete -F _longopt ld
complete -F _service /etc/init.d/apparmor
complete -F _longopt enscript
complete -F _longopt irb
complete -F _command xargs
complete -j -P '"%' -S '"' jobs
complete -F _service service
complete -F _longopt tail
complete -F _longopt unexpand
complete -F _longopt netstat
complete -o dirnames -o filenames -F _apport-cli apport-cli
complete -F _longopt ls
complete -F _command tsocks
complete -F _longopt diff
complete -o nospace -F _cd pushd
complete -v unset
complete -F _service /etc/init.d/whoopsie
complete -F _longopt csplit
complete -F _known_hosts rsh
complete -F _command exec
complete -F _longopt shar
complete -F _longopt vdir
complete -F _longopt sum
complete -F _longopt nm
complete -F _service /etc/init.d/gdomap
complete -F _longopt nl
complete -F _user_at_host ytalk
complete -F _service /etc/init.d/plymouth-log
complete -j -P '"%' -S '"' disown
complete -o dirnames -o filenames -F _apport-bug apport-bug
complete -F _longopt bash
complete -F _service /etc/init.d/procps
complete -u sux
complete -F _longopt md5sum
complete -A stopped -P '"%' -S '"' bg
complete -F _longopt objcopy
complete -F _longopt bc
complete -F _longopt paste
complete -F _service /etc/init.d/haveged
complete -F _service /etc/init.d/grub-common
complete -F _longopt dir
complete -b builtin
complete -F _longopt a2ps
complete -F _root_command really
complete -F _longopt shasum
complete -F _command ltrace
complete -F _service /etc/init.d/hwclock.sh
complete -F _service /etc/init.d/irqbalance
complete -F _known_hosts traceroute6
complete -F _longopt date
complete -F _service /etc/init.d/anacron
complete -F _longopt cat
complete -F _longopt readelf
complete -F _longopt awk
complete -F _known_hosts dig
complete -F _user_at_host talk
complete -F _longopt sha512sum
complete -F _longopt seq
complete -F _longopt mkdir
complete -F _longopt sha224sum
complete -F _service /etc/init.d/pulseaudio-enable-autospawn
complete -A helptopic help
complete -F _minimal ''
complete -F _service /etc/init.d/keyboard-setup.sh
complete -F _longopt df
complete -F _command eval
complete -A setopt set
complete -F _longopt chroot
complete -F _longopt sort
complete -F _command do
complete -F _service /etc/init.d/dbus
complete -F _longopt pr
complete -F _longopt colordiff
complete -F _service /etc/init.d/saned
complete -F _longopt du
complete -F _longopt fmt
complete -F _service /etc/init.d/bluetooth
complete -F _longopt sed
complete -F _service /etc/init.d/spice-vdagent
complete -F _longopt gperf
complete -F _command time
complete -F _service /etc/init.d/udev
complete -F _longopt wc
complete -F _root_command fakeroot
complete -u slay
complete -F _longopt grub
complete -F _service /etc/init.d/cron
complete -F _longopt rmdir
complete -F _service /etc/init.d/uuidd
complete -A shopt shopt
complete -F _apport-collect apport-collect
complete -F _service /etc/init.d/smartmontools
complete -o dirnames -o filenames -F _apport-bug ubuntu-bug
complete -F _known_hosts ftp
complete -F _longopt units
complete -F _longopt uname
complete -F _longopt touch
complete -F _longopt ldd
complete -F _command then
complete -F _known_hosts rlogin
complete -F _service /etc/init.d/sddm
complete -F _command command
complete -F _longopt sha384sum
complete -F _known_hosts fping6
complete -F _longopt rm
complete -F _service /etc/init.d/cryptdisks
 
Old 01-13-2024, 12:32 PM   #13
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
I said vi works perfectly but now it doesn't for some reason, maybe it actually never did.

My motive is to browse frequent dirs faster. But is this even a common practice? Is there a better method?

* answer

Code:
$ cd $shortcut
$ cd ./<tab>
This was fun. Thank you for all the help MadeInGermany, and everyone.

Last edited by disk_bearing; 01-13-2024 at 01:12 PM.
 
Old 01-13-2024, 01:40 PM   #14
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
My test system does not have the bash-completion package installed. The complete command shows nothing.

I think it only modifies and extends the default behavior.
And I think your bash version has a bug.
Such a bug had already occurred 13 years ago:
https://bbs.archlinux.org/viewtopic.php?id=115548
And again 11 years ago:
https://bugs.debian.org/cgi-bin/bugr...cgi?bug=698721
And again 2 years ago:
https://bugzilla.redhat.com/show_bug.cgi?id=2026883

Last edited by MadeInGermany; 01-13-2024 at 02:42 PM.
 
1 members found this post helpful.
Old 01-13-2024, 07:25 PM   #15
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by disk_bearing View Post
In bash when I press tab,
Code:
cd $shortcut/s
becomes
Code:
cd \$shortcut/subdir
and the slash added before $ breaks the command.
You're not alone. I've seen the same thing:
Code:
$ TGT=`pwd`
$ cd someplace else
$ cp file $TGT
works OK but often recalling it and trying to change it, the environment variable has been prefixed with the escape character and, of course, the command fails until I delete it. I figure it's a weird bash thing -- maybe version-dependent. I see this happening on openSUSE where I spend most of the day; I'll have to confirm if the same thing happens on Slackware and/or Raspbian.
 
1 members found this post helpful.
  


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
LXer: The first browser to introduce a second level in the tab bar for managing tab groups: Two-Level Tab LXer Syndicated Linux News 0 03-01-2021 05:50 AM
adding an option to a 'tab' completion + ls whatnoname Linux - Newbie 2 06-07-2005 07:32 AM
tab completion with scp fsbooks Linux - General 5 04-07-2005 03:13 PM
How can I turn on/install tab completion which I am so used to. jimdaworm *BSD 2 04-06-2005 11:25 PM
apt-get tab completion atheist Debian 6 06-11-2004 08:25 PM

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

All times are GMT -5. The time now is 12:04 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