That's what normally the PATH
variable is for. Though, I would not add your whole home-directory to your PATH
. Consider adding a dedicated directory (like ~/bin
) to add to your path your executables.
However, you could add a function to your ~/.bashrc
which allows you to search for and run a script...something like this:
# brun stands for "blindly run"
function brun {
# Find the desired script and store
# store the results in an array.
results=(
$(find ~/ -type f -name "$1")
)
if [ ${#results[@]} -eq 0 ]; then # Nothing was found
echo "Could not find: $1"
return 1
elif [ ${#results[@]} -eq 1 ]; then # Exactly one file was found
target=${results[0]}
echo "Found: $target"
if [ -x "$target" ]; then # Check if it is executable
# Hand over control to the target script.
# In this case we use exec because we wanted
# the found script anyway.
exec "$target" ${@:2}
else
echo "Target is not executable!"
return 1
fi
elif [ ${#results[@]} -gt 1 ]; then # There are many!
echo "Found multiple candidates:"
for item in "${results[@]}"; do
echo $item
done
return 1
fi
}
This is a great script! I changed a bit to meet my need: ` results=($(find ~/ -name "$1")) => results=($(find ./ -type f -name "$1*"))
exec $target ${@:2} => $target ${@:2} ` – fqsxr – 2012-11-06T02:41:29.573
@fqsxr:
-type f
is good idea, yeah. – Bobby – 2012-11-06T08:10:48.433