You can pipe directly from curl to
tr to xclip, so don't have to use a temp file or a lock file.
touch is atomic, so there's no need to touch a different file and move it to the lock file.
You can also negate your conditions so that you don't have a useless
then clause followed by the
else that you actually want.
Code:
#!/bin/bash
###############################################################
# Fetch a random string from www.random.org through HTTPS,
# write it to file and copy it to clipboard.
#
# Script by e633
# DEPENDENCIES: curl, xclip, zenity
###############################################################
num=5
len=10
#Parameters customization
if zenity --question --title "Random.org string fetcher" --text "Personalize parameters?
NOTE: the amount of randomness you can fetch in 24hrs is limited."
then
if !(num="$(zenity --entry --title="How many" --text="How many strings? (max 10000)" --entry-text "$num")"); then
num=5
fi
if !(len="$(zenity --entry --title="Length" --text="Length of each string? (max 20)" --entry-text "$len")"); then
len=10
fi
fi
curl --silent "https://www.random.org/strings/?num=$num&len=$len&digits=on&upperalpha=on&loweralpha=on&unique=off&format=plain&rnd=new" | \
tr -d '\012' | \
xclip -selection clipboard
-
thobbs