I am writing a bash script and I would like to verify if a string is a shell reserved word (like if, for, alias, etc...).
How can I do this?
#!/bin/bash
string="$1"
if [[ $(type "$string" 2>&1) == "$string is a shell"* ]]; then
    echo "Keyword $string is reserved by shell"
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With