Bash shell aliases and functions


#1

I was trying to figure out how to do aliases in bash shell on kiki, but it looks like alias is not a command available in bash on kiki ( not found, nothing found with a whereis), so I was trying to instead do a bash function. The Bash ref. manual says functions are preferred in almost all cases. So I attempted a simple test function to see if I figured the syntax out: function ls { ls -lt; } When I type ls into the bash shell I just get a long hang. Eventually I came back to the bash prompt. I hope I didn’t chew up too much cpu for everyone else. On my local Solaris system, the attempted function eventually gives me a Segmentation Fault. What is the deal with alias on kiki and what is the proper bash function syntax.


#2

it looks like alias is not a command available in bash on kiki ( not found, nothing found with a whereis)

alias is a shell built-in, meaning it’s not an external command in your path. To set bash aliases, use the following syntax:

alias foo="echo this is a test" … and test it like so:

$ foo this is a test Add to .bash_profile as needed.


If you want useful replies, ask smart questions.


#3

builtins don’t show up in whereis or which.

jazz:$ type alias
alias is a shell builtin

alias foo=bar
alias ll=“ls -al”

Also, keep in mind that bash aliases do not go in ~/.alias (unless you specifically source this file… just put them in your .bashrc / .bash_profile


#4

Cripes! The one clue I was missing and wasn’t finding anywhere in sec. 6.6 of the Bash reference was the need for the = in the alias syntax. I was able to find out about .bash_profile and .bashrc, however. Thanks, both of you.

Still, what’s the syntax for bash functions?