Modify the cdh function to allow the user to specify a partial name of a directory in the history file preceded by a dash:
/etc: cdh –l
0 /users/pat
1 /tmp
2 /users/steve
3 /usr/spool/uucppublic
4 /usr/local/bin
5 /etc
/etc: cdh –pub
/usr/spool/uucppublic: cdh –bin
/usr/local/bin
The necessary code is added to the case statement just before the *) default case. Here's one way to add this feature, including an error message if there's no match found:
-[a-z]*) # find partial match in CDHIST
for dir in "${CDHIST[@]}"
do
if [ ! -z "$(echo $dir | grep "${1#-}")" ] ; then
# matched $dir, moving there
cdh $dir
return # done. uses first match
fi
done
echo "Error: No match for $1 found in CDHIST"
return ;;
You might also like to view...
BASIC was the first programming language ever developed
Indicate whether the statement is true or false
An antistatic bag is commonly used to hold laptop screws
Indicate whether the statement is true or false