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



Reply
 
Thread Tools Rate Thread Display Modes
Old 03-05-2002, 08:19 PM   #1
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
bash alias fiddling

I've always had this set up in my aliases.mine for tcsh (btw, "lc" is another alias to do "ls" in color):

Code:
alias cdd  'cd \!*;echo $cwd; lc -FC'
which automatically outputs the contents of a directory when I get there.

But it does not work perfectly in bash:

Code:
alias cdd='cd \!*;echo $cwd; lc -FC'
resides in my .bashrc and it functions ok but bash barfs this up every time I use cdd:

Code:
bash: cd: !*: No such file or directory
even though I have the ! escaped with a \
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-05-2002, 08:35 PM   #2
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
bash don't take kindly to csh style ( !* ) args...

in fact, bash aliases don't allow args. bash functions do, tho...

the args are:

$* expands to $1 $2 $3 ...

$@ expands to "$1 $2 $3 ..."

try bash functions:
Code:
ll () { ls -FlAh --color "$@" | more ; }

ff () { find . -name ${1} -print ; }

zfw () { fgrep -i "$*" /usr/share/dict/web2 | less ; }
mervTormel is offline   Reply With Quote
Old 03-05-2002, 08:45 PM   #3
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Thanks...do bash functions also "live" in .bashrc?
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-05-2002, 08:50 PM   #4
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
this might be closer to your cdd

$ cdd () { cd ${1} ; echo $PWD ; lc -FC ; }

but your lc function inside cdd might be a little bit high overhead. i'd explicitly spell out commands in functions. might make debugging them easier.

$ cdd () { cd ${1} ; echo $PWD ; ls -FC --color ; }

you can list functions with the declare or typeset command

note that the final semicolon before the end brace is required.

a function is like a full blown script, it can have local variables, control and conditionals in it too. it might behoove you to treat it like a script.

bash functions defined in .bashrc will be available in sub-shells and shell-escapes ( like ! in vi )

also note, functions are exec'd in the current process, rather than a fork & exec process.
mervTormel 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.