Created
April 27, 2023 17:32
-
-
Save adjam/dc33161d58d81d6ff20b5ae014748cf9 to your computer and use it in GitHub Desktop.
Bash function to create a unique filename
This file contains 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
unique_name() { | |
local base=$1 | |
local ext=$2 | |
local name="${base}.${ext}" | |
if [[ -e $name || -L $name ]]; then | |
i=1 | |
while [[ -e "${base}-${i}.${ext}" || -L "${base}-${i}.${ext}" ]]; do | |
let i++ | |
done | |
name="${base}-${i}.${ext}" | |
fi | |
echo $name; | |
} | |
# filename=$(unique_name "foo-$(date +%Y-%m-%d)" "tgz") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment