Skip to content

Instantly share code, notes, and snippets.

@Tuhin-thinks
Created September 8, 2024 21:36
Show Gist options
  • Save Tuhin-thinks/415c8db80dad5f321c2e3f4bfc257ba7 to your computer and use it in GitHub Desktop.
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
#!/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
@Tuhin-thinks
Copy link
Author

Usage

$ install-latest-of.sh "discord*"
Executing: ls -t1 discord* | head -1
Installing discord-0.0.63.deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment