Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 01-30-2004, 11:52 AM   #1
Andrea
Triple-A Player
 
Join Date: Jul 2002
Posts: 63
A little help with bash.

Hi,
I have 3 questions about bash. Here they are:

1) How can I get completions at the command line similar to those I was used with tcsh? Does Fink's package bash-completion work under 10.3?

2) How can I set up an alias that pipes ls result to less?
I've tried with:
Code:
alias ll='ls -al "$@"|less'
but without success.

3) When I create a new shell not via Terminal app, the new shell doesn't source my .bash_profile where I put all my alias and so on. How can I fix this?

Thanks,
Andrea.
Andrea is offline   Reply With Quote
Old 01-30-2004, 12:56 PM   #2
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
1. completion (shopt progcomp) is enabled by default in bash. fink's bash completion pkg works well with >= bash v2.04

is some completion failing?

2. bash aliases don't do variable substitutions. create a bash function for that case:

Code:
$ declare -f ll
ll () 
{ 
    TERM=ansi /bin/ls -GFlAho "$@" | less -FR
}
3. .bash_profile should contain noisy things (reports like uptime, who, df, fortune, date) you want to see in a login shell (new term window) .bashrc should run silent (no term output) and be used for alias/function definitions, or source the appropriate files from there.

it's important to know how the startup sequence works and the difference between a login shell and a subshell [ at the bash prompt, enter bash to start a subshell. note that .bash_profile wasn't sourced, but .bashrc was ]

it is a convention that .bash_profile source .bashrc

i refer you to the man pages for bash. i know it seems daunting, but it'll serve you well to be familiar with the fundamentals.
mervTormel is offline   Reply With Quote
Old 01-30-2004, 01:58 PM   #3
Andrea
Triple-A Player
 
Join Date: Jul 2002
Posts: 63
Quote:
Originally posted by mervTormel
1. completion (shopt progcomp) is enabled by default in bash. fink's bash completion pkg works well with >= bash v2.04
is some completion failing?

Well it seems not to work at all here. For example when I type
Code:
$ man ba
and I hit the tab key I'd like to see
Code:
$ man bash
. Further I'd like to implement some completions my own (fink commands, list of hosts, etc...)

Quote:
2. bash aliases don't do variable substitutions. create a bash function for that case:

Thanks.

Quote:
3. .bash_profile should contain noisy things (reports like uptime, who, df, fortune, date) you

....

I'll look at the man pages...

Cheers,
Andrea.
Andrea is offline   Reply With Quote
Old 01-30-2004, 02:09 PM   #4
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
well, if you were to install fink's bash-completion pkg, it provides man page completion, among many others.

the default completion is pretty simple, and programming your own completion can be complex.

e.g.
Code:
$ grep -C1 'complete.* man' /sw/etc/bash_completion
[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
  -o $UNAME = FreeBSD -o $UNAME = SunOS ] && complete -F _man $filenames man
mervTormel is offline   Reply With Quote
Old 01-30-2004, 02:46 PM   #5
gatorparrots
Major Leaguer
 
Join Date: Dec 2002
Posts: 441
Quote:
Originally posted by mervTormel
well, if you were to install fink's bash-completion pkg, it provides man page completion, among many others.

the default completion is pretty simple, and programming your own completion can be complex.

Which is where zsh comes in...
gatorparrots is offline   Reply With Quote
Old 01-30-2004, 03:16 PM   #6
Andrea
Triple-A Player
 
Join Date: Jul 2002
Posts: 63
Thanks a lot to mervTormel. Everything works as I wanted. Regarding completions I'll look at the fink's package, I hope it'll fulfill my needs.

For gatorparrots:
I've heard something about zsh, but I'm not sure taht changing Apple's default would be a good idea.

Cheers,
Andrea.
Andrea is offline   Reply With Quote
Old 01-30-2004, 03:29 PM   #7
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Quote:
Originally posted by Andrea
...I've heard something about zsh, but I'm not sure taht changing Apple's default would be a good idea.

changing the default is harmless. migrating from one shell to another takes a bit of planning, dedication and work.

if you are new to bash, you might want to skip straight on over to zsh. it has a lot of great features at a ~steep learning curve price.
mervTormel is offline   Reply With Quote
Old 01-30-2004, 06:40 PM   #8
Andrea
Triple-A Player
 
Join Date: Jul 2002
Posts: 63
Quote:
Originally posted by mervTormel
changing the default is harmless. migrating from one shell to another takes a bit of planning, dedication and work.

if you are new to bash, you might want to skip straight on over to zsh. it has a lot of great features at a ~steep learning curve price.

Thanks for your suggestions. I'll consider zsh.

Cheers,
Andrea.
Andrea is offline   Reply With Quote
Old 01-30-2004, 07:04 PM   #9
gatorparrots
Major Leaguer
 
Join Date: Dec 2002
Posts: 441
dipping the toes into zsh

Gary Kerbaugh's zsh setup scripts makes jumping into zsh in an OS X environment fairly easy:
http://kerbaugh.uncfsu.edu/zsh.tar.gz

W.G. Scott has a nice primer on zsh under OS X here:
http://www.chemistry.ucsc.edu/~wgscott/xtal/zsh.html
gatorparrots is offline   Reply With Quote
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 On
HTML code is Off

Forum Jump



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


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.