Created
September 8, 2024 21:36
-
-
Save Tuhin-thinks/415c8db80dad5f321c2e3f4bfc257ba7 to your computer and use it in GitHub Desktop.
Bash script to install the latest version of a file using dpkg -i
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pattern="$1" | |
shopt -s nullglob | |
command="ls -t1 "$pattern" | head -1" | |
echo "Executing: $command" | |
fileName=$(eval $command) | |
shopt -u nullglob | |
if [[ -n $fileName ]]; then | |
echo "Installing $fileName" | |
sudo dpkg -i $fileName | |
if [ $? -eq 0 ]; then | |
echo "Installed $fileName successfully" | |
# remove the file | |
rm -iv $fileName | |
else | |
echo "Failed to install $fileName" | |
fi | |
else | |
echo "No file found" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage