Skip to content

Instantly share code, notes, and snippets.

@StefanoBelli
Created August 7, 2018 10:29
Show Gist options
  • Select an option

  • Save StefanoBelli/ead2177a1a367ae22fcf798be17ca3a1 to your computer and use it in GitHub Desktop.

Select an option

Save StefanoBelli/ead2177a1a367ae22fcf798be17ca3a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# guess prefix based on an installed program
#
# give a program on your own
# ./guess-prefix.sh gcc
#
# or let the program consider "make"
# ./guess-prefix.sh
#
# STDOUT: /usr
PROG="$1"
if [ $# -lt 1 ]; then
PROG="make"
fi
WHAT=$(which $PROG)
ARR=(${WHAT//// })
FINAL_STR=""
for p in ${ARR[@]}; do
if [[ $p == "bin" ]]; then
break
fi
FINAL_STR=$FINAL_STR"/"$p
done
echo $FINAL_STR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment