Hello.
I have installed 3-d party utilities, like gnu utilites,and adjusted the path. In order to make something work for someone else, I have to figure out which utility I use when I test. Adjusting away from /opt/local/bin, and /usr/local/bin when I have to.
I also type cat which utility
a lot to figure out what scripts look like. But I also type alias to see my aliases in .bashrc, and I use the builtin type function in bash to display the contents of functions (help type).
The shell function below, which should be included in your .bashrc file, or sourced into it. Solves this problem, as it will display any alias with a name, any function, the contents of a shell script, and the type of any binaries, in the executable order which is alias, function, and what comes first in the path.
[code]function rap(){
if [ $# -ne 1 ] ; then
echo “rap: Needs a command name!” >|/dev/stderr
return 1
fi
type -t “$1” 2>&1 |grep “function” >/dev/null && type “$1” && return 0
type -a "$1" 2>&1 | sed -ne '/aliased/p'
type -a "$1" 2>&1 | sed -ne '/shell builtin/p'
type -t "$1" 2>&1 |egrep "(aliased|builtin)" 2>&1 >/dev/null && return 0
rapTMPFILE=$(mktemp -q /tmp/rap.XXXXXX)
if [ $? -ne 0 ]; then
echo "rap: Can't create temp file, exiting." >2
exit 1
fi
type -a "$1" |sed -ne '/'"$1"' is \// s//\//p' >|$rapTMPFILE
exec 3<&0
exec 0<$rapTMPFILE
while read line
do
# use $line variable to process line
fileTp=$(/usr/bin/file $line)
echo $fileTp
echo $fileTp | grep -q "script text executable"
if [ $? -eq 0 ] ; then
cat $line
fi
done
exec 0<&3 function rap(){
if [ $# -ne 1 ] ; then
echo "rap: Needs a command name!" >|/dev/stderr
return 1
fi
type -t "$1" 2>&1 |grep "function" >/dev/null && type "$1" && return 0
type -a "$1" 2>&1 | sed -ne '/aliased/p'
type -a "$1" 2>&1 | sed -ne '/shell builtin/p'
type -t "$1" 2>&1 |egrep "(aliased|builtin)" 2>&1 >/dev/null && return 0
rapTMPFILE=$(mktemp -q /tmp/rap.XXXXXX)
if [ $? -ne 0 ]; then
echo "rap: Can't create temp file, exiting." >2
exit 1
fi
type -a "$1" |sed -ne '/'"$1"' is \// s//\//p' >|$rapTMPFILE
exec 3<&0
exec 0<$rapTMPFILE
while read line
do
# use $line variable to process line
fileTp=$(/usr/bin/file $line)
echo $fileTp
echo $fileTp | grep -q "script text executable"
if [ $? -eq 0 ] ; then
cat $line
fi
done
exec 0<&3
}[/code]