LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-24-2007, 02:10 PM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
!command expansion in csh vs. bash


In tcsh, when I type
Code:
tcsh% !command
, followed by a tab, it autocompletes to show the actual command.
In bash, on the other hand, when I type
Code:
bash# !command
, followed by a tab, it does not autocomplete and I have no way of knowing what command is actually going to be executed. However, noone wants to use The Clown SHell; can I get this feature in bash?
 
Old 08-24-2007, 02:27 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,015
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
bash# command (no exclamation) + tab DOES autocomplete
unless there is more than one match in which case hitting tab a second time will give you the list of matches.
 
Old 08-24-2007, 03:33 PM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 207Reputation: 207Reputation: 207
Quote:
bash# command (no exclamation) + tab DOES autocomplete
Indeed. Not of any particular worth for long commands you'd want to rip out of the history due to their length, though.
 
Old 08-24-2007, 04:13 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Bash does support history expansion. There's a fair bit of info in the man page so I won't quote it, but if you search in it for HISTORY EXPANSION (in upper case) it's explained reasonably well.

Last edited by gilead; 08-25-2007 at 12:08 AM.
 
Old 08-24-2007, 04:59 PM   #5
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,015
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Quote:
Originally Posted by jhwilliams View Post
Indeed. Not of any particular worth for long commands you'd want to rip out of the history due to their length, though.
OK you're talking about history rather than expansion.

My own preference is to do "set -o vi" as I do with ksh. Doing "esc-k" then will let me scroll through shell history. Once there I can do /pattern to search for a specific pattern in shell history. One of my favorites in doing this however is that I can simply hit "v" once I have the command back and that will open a vi session with the command in it - great for working out complicated pipelines then incorporating them within for loops.
 
Old 08-24-2007, 05:07 PM   #6
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 207Reputation: 207Reputation: 207
Quote:
Originally Posted by jlightner View Post
My own preference is to do "set -o vi"
Hm, trying it out now - not too shabby.
 
Old 08-25-2007, 02:33 AM   #7
fvu
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
When you specify `set show-all-if-ambiguous on' in .inputrc (the readline configuration file), you only have to press TAB once in bash to get the list of possible completions. Re-login after modifications:

Code:
# Produce list of all possible completions at single tab
set show-all-if-ambiguous on
See also:
http://www.fvue.nl/wiki/Bash:_My_configuration


Freddy Vulto
http://fvue.nl/wiki/Bash
 
Old 08-25-2007, 09:52 PM   #8
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 207Reputation: 207Reputation: 207
Quote:
Originally Posted by fvu View Post
Line 32 of your .bashrc that sets the main prompt - what is going on in this line?

Code:
export PS1=$'\[\e[0;34m\]\!\[\e[0m\]\[\e[1;32m\]$(stoppedjobs)\[\e[0m\]:\u@\h:\w> '
 
Old 08-27-2007, 03:29 PM   #9
fvu
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
This is an explanation of my bash `PS1' setting as can be found at http://fvue.nl/wiki/Bash:_My_configuration

Code:
# \[\e[0;34m\]   : start blue
# \!             : show history number of command
# \[\e[0m\]      : stop blue
# \[\e[1;32m\]   : start light green
# $(stoppedjobs) : execute shell function `stoppedjobs' which
#                  returns `%' plus number of jobs
#                 (see http://www.fvue.nl/wiki/Bash:_My_configuration)
# \[\e[0m\]      : stop light green
# \u             : show username
# \h             : show hostname
# \w             : show working directory
export PS1=$'\[\e[0;34m\]\!\[\e[0m\]\[\e[1;32m\]$(stoppedjobs)\[\e[0m\]:\u@\h:\w> '
Example prompt:
502%1:freddy@pluto:/usr/local>
See also: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/


Freddy Vulto
http://fvue.nl/wiki/Bash
 
Old 08-27-2007, 05:04 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,354

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
<ctrl>-r ???
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash variable string expansion Reginald0 Linux - Software 5 02-13-2007 10:38 AM
Bash variables expansion olaola Linux - Newbie 4 10-16-2006 11:45 AM
Script for csh or bash unihiekka Programming 5 10-15-2005 09:51 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration