Skip to content

Instantly share code, notes, and snippets.

@Niall47
Created October 18, 2023 08:03
Show Gist options
  • Save Niall47/cd334771f25f14a39a917dc364309b42 to your computer and use it in GitHub Desktop.
Save Niall47/cd334771f25f14a39a917dc364309b42 to your computer and use it in GitHub Desktop.
Find binary script. Runs -v on each instance it finds.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <executable_name>"
exit 1
fi
executable="$1"
IFS=':' read -ra path_dirs <<< "$PATH"
found=false
for dir in "${path_dirs[@]}"; do
if [ -x "$dir/$executable" ]; then
echo "Found: $dir/$executable"
found=true
"$dir/$executable" -v
fi
done
if [ "$found" = false ]; then
echo "Executable $executable not found in PATH."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment