use -z to check if a string is empty or not

Previously I used:
    [[ $STRING == "" ]] && do_something
To check if a string was empty or not, but this can be simplified a lot by writing:
    [ -z $STRING ] && do_something
This commit is contained in:
Siddharth Dushantha 2020-03-20 16:10:40 +01:00 committed by GitHub
parent 791f26fe54
commit 01dbabf5a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

12
kunst
View File

@ -183,9 +183,9 @@ pre_exit() {
main() {
[[ $KUNST_MUSIC_DIR != "" ]] && MUSIC_DIR=$KUNST_MUSIC_DIR
[[ $KUNST_SIZE != "" ]] && SIZE=$KUNST_SIZE
[[ $KUNST_POSITION != "" ]] && POSITION=$KUNST_POSITION
[ -z $KUNST_MUSIC_DIR ] && MUSIC_DIR=$KUNST_MUSIC_DIR
[ -z $KUNST_SIZE ] && SIZE=$KUNST_SIZE
[ -z $KUNST_POSITION ] && POSITION=$KUNST_POSITION
# Flag to run some commands only once in the loop
FIRST_RUN=true
@ -231,9 +231,9 @@ main() {
while true; do
mpc idle player &>/dev/null && (mpc status | grep "\[playing\]" &>/dev/null) && break
done
if [ ! $SILENT ]; then
echo "kunst: received event from mpd"
fi
[ ! $SILENT ] && echo "kunst: received event from mpd"
if [ "$VIEWER" = 'imv' ]; then
imv-msg "$(cat /tmp/kunst.pid)" close all
imv-msg "$(cat /tmp/kunst.pid)" open "$COVER"