null_reflections
Legendary Coder
This script is actually kinda unnecessary on a linux system because you just have to try running a program through the terminal in order to figure out that you haven't installed it:
However, if you are looking for more information, then this script might be able to lead you figuring out problems sooner:
I used the "while read" concept here, but "readarray" is potentially better and less deprecated.
Code:
kerblunk
kerblunk: command not found
However, if you are looking for more information, then this script might be able to lead you figuring out problems sooner:
Code:
#!/bin/bash
#script idea: tell user if a file is executable or is included in path
SCRIPT=$0
#instructions
if [ $# -lt 1 ]; then
echo "Usage:${SCRIPT##*/} [program-name]"
fi
#creates file listing path directories
echo $PATH | awk 'BEGIN {RS=":"} {print}' | sed '/^$/d' > path-dirs
#loops through directories and tells user if file exists but is not executable
while read -r line; do
if [ -f "$line/$1" ] && ! [ -x "$line/$1" ]; then
echo "$1 is in \$PATH but is NOT executable"
echo "Location: $line"
exit 0
fi
done < path-dirs
#tells user program is ready to use
while read -r line; do
if [ -x "$line/$1" ]; then
echo "$line/$1 is in \$PATH and is executable"
echo "Location: $line"
exit 0
fi
done < path-dirs
#clean-up
rm path-dirs
#program does is not in path
echo "$1 does not exist in \$PATH"
I used the "while read" concept here, but "readarray" is potentially better and less deprecated.