The unquoted ?
is expanded as a wildcard by the shell. You have two files with single-character names in the current directory.
The fix is to generally quote everything, unless you specifically require the shell to perform wildcard expansion and whitespace tokenization on a value.
The wildcard gets expanded in the array assignment, so you could quote that:
check=("$(ps -e | awk -v prg="$prg" '$0 ~ prg {print "kILL " $4" "$1 " ? [y/n]"}')")
but then you might was well not use an array. But then you might as well just capture the PID.
pid=$(ps -e | awk -v prg="$prg" '$0 ~ prg { print $1 }')
This loses the process name, though. You could refactor the script to print just the machine-readable parts, and then use those in a print statement.
check=($(ps -e | awk -v prg="$prg" '$0 ~ prg { print $1, $4 }'))
read -p "kILL ${check[1]} ${check[0]}? [y/n]"
(Incidentally, aligning the question mark with the previous word, as is the convention in English orthography, would also fix your problem, though sort of accidentally. Notice also how to avoid the useless use of grep
in the examples above.)