LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   !command expansion in csh vs. bash (http://www.linuxquestions.org/questions/linux-software-2/command-expansion-in-csh-vs-bash-579545/)

jhwilliams 08-24-2007 02:10 PM

!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?

MensaWater 08-24-2007 02:27 PM

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.

jhwilliams 08-24-2007 03:33 PM

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.

gilead 08-24-2007 04:13 PM

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.

MensaWater 08-24-2007 04:59 PM

Quote:

Originally Posted by jhwilliams (Post 2869545)
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.

jhwilliams 08-24-2007 05:07 PM

Quote:

Originally Posted by jlightner (Post 2869652)
My own preference is to do "set -o vi"

Hm, trying it out now - not too shabby.

fvu 08-25-2007 02:33 AM

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

jhwilliams 08-25-2007 09:52 PM

Quote:

Originally Posted by fvu (Post 2869945)

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> '

fvu 08-27-2007 03:29 PM

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

syg00 08-27-2007 05:04 PM

<ctrl>-r ???


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