Auto Install Missing Programs on linux using bashrc
Page 1 of 1
Auto Install Missing Programs on linux using bashrc
- Code:
sudo gedit ~/.bashrc
- Code:
# Function to handle missing commands and install them
command_not_found_handle() {
local cmd=$1
# Check if the command is available
if ! command -v "$cmd" &> /dev/null; then
echo "Command '$cmd' not found. Installing..."
sudo apt-get update -y
sudo apt-get install -y "$cmd"
# Check if the installation was successful
if command -v "$cmd" &> /dev/null; then
echo "Command '$cmd' installed successfully."
else
echo "Failed to install '$cmd'."
fi
else
# If the command exists, handle it normally
"$@"
fi
}
# Override the default command_not_found_handle function
if [ -n "$BASH_VERSION" ]; then
command_not_found_handle() {
local cmd=$1
if ! command -v "$cmd" &> /dev/null; then
echo "Command '$cmd' not found. Installing..."
sudo apt-get update -y
sudo apt-get install -y "$cmd"
if command -v "$cmd" &> /dev/null; then
echo "Command '$cmd' installed successfully."
else
echo "Failed to install '$cmd'."
fi
else
"$@"
fi
}
fi
Similar topics
» bashrc function to auto installs missing linux programs and missing python modules!
» how to install kde 4.8 in linux
» using figlet in bashrc in linux
» Linux Extract Archive Bashrc Function
» Bashrc function to take screenshot on linux for raspberry pi
» how to install kde 4.8 in linux
» using figlet in bashrc in linux
» Linux Extract Archive Bashrc Function
» Bashrc function to take screenshot on linux for raspberry pi
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum