Solved it's simple bash substitution and its pissing me off.

I have a script written by someone else to change backgrounds in a multitude of desktops and window managers that I've modified and now I am modding it again to , when an image is used move it to a different directory to insure all images get to be displayed, then when that source dir is empty just move everything back to do it all over again. This one simple thing is not working. the variables all have values but it is not substituting directories in the command.
.
under XFCE is where I am working on until i get it to work. I also added a function to make it hopefully easier when I this one DT working. just plug in the function name. it does not work in the function nor in the body of the script.

the substitution
Code:
   echo "
    $WP
    $from
    $moveto
    "
    fileis=${WP/from/moveto}
    notify-send "WP" "$WP"
    notify-send "$from" "$moveto"
    echo "from- moreto $from $moveto"
    notify-send "here" "$fileis"
    movewallpaper
output running it on CLI , it works like it should
Code:
file=/from/here/bob.jpg ; from=/from/here ; to=/to/here/ ; move=${file/from/to} ; echo $move
/to/here/bob.jpg
output running it from the script using set -x
Code:
+ echo '
    /media/storage/wallpaper/test/Ariana_Grande/Ariana_Grande-1625x1080-43rxq6.jpg
    /media/storage/wallpaper/test
    /media/storage/wallpaper/background-storage
    '

    /media/storage/wallpaper/test/Ariana_Grande/Ariana_Grande-1625x1080-43rxq6.jpg
    /media/storage/wallpaper/test
    /media/storage/wallpaper/background-storage
   
+ fileis=/media/storage/wallpaper/test/Ariana_Grande/Ariana_Grande-1625x1080-43rxq6.jpg
+ notify-send WP /media/storage/wallpaper/test/Ariana_Grande/Ariana_Grande-1625x1080-43rxq6.jpg
+ notify-send /media/storage/wallpaper/test /media/storage/wallpaper/background-storage
It see all of the variables needed but does not preform the task. I don't know why.

sctipt:
Code:
#!/bin/bash
    set -x
# This script is run by Variety when a new wallpaper is set.
# You can use bash, python or whatever suits you for the script.
# Here you can put custom commands for setting the wallpaper on your specific desktop environment
# or run commands like notify-send to notify you of the change, or you can
# run commands that would theme your browser, login screen or whatever you desire.
#
# PARAMETERS:
# $1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper
# (after effects, clock, etc. are applied).
#
# $2: The second passed parameter is "auto" when the wallpaper is changed automatically (i.e. regular change), "manual"
# when the user has triggered the change or "refresh" when the change is triggered by a change in quotes, clock, etc.
#
# $3: The third passed parameter is the absolute path to the original wallpaper image (before effects, clock, etc.)
#
# EXAMPLE:
# echo "$1" # /home/username/.config/variety/wallpaper/wallpaper-clock-fac0eef772f9b03bd9c0f82a79d72506.jpg
# echo "$2" # auto
# echo "$3" # /home/username/Pictures/Wallpapers/Nature/green-tunnel-1920x1080-wallpaper-861.jpg
#images=/home/userx/Images/wallheaven
#images=/home/userx/Pictures/wallpapers

from=/media/storage/wallpaper/test

#from=/media/storage/wallpaper/backgrounds
moveto=/media/storage/wallpaper/background-storage
[[ ! -d "$moveto" ]] && mkdir -p $"moveto" ;

images="$from"
notify-send  "xfce4-setwallpaper sctipt" "source= $images"
#to insure all images are used for desktop
#wallpaper
movewallpaper() {
   notify-send  "movewallpaper" "WP= $WP"
  
    #image is set move it to wallpapers and log it
    #in a fime in home
     #to=${WP/from/moveto}
     notify-send "to" "$to"
    #send path and image name to file in home
    echo "$to" > "$HOME"/mhsetrootimagefile
   
    #remove name from path
    to=${to%/*}
    echo $to
    mkdir -pv "$to"
    mv -v "$WP" "$to"
}
#source images directory
empty=$(find $images -type f | wc -l)

#check storage place if empty
#then move holding place back to storage place
case $empty in
    0)
        holdingimg=$(find "$images" \( -type f -name "*.jpg" -o -type f -name "*.png" \) | wc -l)
        if [[ $holdingimg -gt '0' ]] ; then
            notify-send  "Images moved to" "$from"
            while read f
            do
                a=$(dirname $f)
                substitute=${f/a/from}
                if [[ ! -d "$substitute" ]] ;
                then
                    mkdir -p "$substitute"
                    mv "$f" "$substitute"
                else
                    mv "$f" "$substitute"
                fi
            done < <(find "$moveto" \( -type f -iname "*.jpg" -o -type f -iname "*.png" \) )
        elif [[ $holdingimg -le '0' ]] ; then
            notify-send " no images to be found in $favimages
            or
            $holding
            exiting ..."
             exit
        fi
        ;;
    1)
        img=$images/$(ls $images)
        ;;
esac
#put list in bash array named images
mapfile -t images < <(find "$images" \( -type f -name "*.jpg" -o -type f -name "*.png" \))

# Here you may apply some additional custom operations on the wallpaper before it is applied.
# In the end put the path to the actual final wallpaper image file in the WP variable.
# The default is to simply set WP=$1.
#img=${images[$RANDOM % ${#images[@]} ]}
#WP=$1
WP=${images[$RANDOM % ${#images[@]} ]}



# Enlightenment
# Needs Modules/System/DBus Extension loaded to work
if [[ "$DESKTOP" == *"Enlightenment"* ]] || [[ "$DESKTOP" == *"Moksha"* ]]; then

    OUTPUT_DIR="$HOME/.e/e/backgrounds"

    TEMPLATE='
    images { image: "@IMAGE@" USER; }
    collections {
      group {
      name: "e/desktop/background";
      data { item: "style" "4"; item: "noanimation" "1"; }
      max: @WIDTH@ @HEIGHT@;
      parts {
        part {
        name: "bg";
        mouse_events: 0;
        description {
          state: "default" 0.0;
          aspect: @ASPECT@ @ASPECT@;
          aspect_preference: NONE;
          image { normal: "@IMAGE@"; scale_hint: STATIC; }
        }
        }
      }
      }
    }
    '

    OFILE="$OUTPUT_DIR/variety_wallpaper_$RANDOM"

    DIMENSION="$(identify -format "%w/%h" "$WP")"

    if [ ! -z "$DIMENSION" ]; then
        WIDTH="$(echo "$DIMENSION" | cut -d/ -f1)"
        HEIGHT="$(echo "$DIMENSION" | cut -d/ -f2)"
        IMAGE="$(echo "$WP" | sed 's/[^[:alnum:]_-]/\\&/g')"

        if [ -z "$HEIGHT" ] || [ "$HEIGHT" = "0" ]; then
            ASPECT="0.0"
            echo "$WP" > $HOME/"/mhsetrootimagefile"
        else
            ASPECT="$(echo "scale=9; $DIMENSION" | bc)"
            echo "$WP" > $HOME/"/mhsetrootimagefile"
        fi
    fi

    printf "%s" "$TEMPLATE" | \
    sed "s/@ASPECT@/$ASPECT/g; s/@WIDTH@/$WIDTH/g; s/@HEIGHT@/$HEIGHT/g; s|@IMAGE@|$IMAGE|g" > "$OFILE.edc"
    edje_cc "$OFILE.edc" "$OFILE.edj" 2>/dev/null
    rm "$OFILE.edc"

    ## Get the current number of virtual desktops
    desk_x_count=$(enlightenment_remote -desktops-get | awk '{print $1}')
    desk_y_count=$(enlightenment_remote -desktops-get | awk '{print $2}')

    ## Get the current number of screens
    screen_count=1
    # If xrandr is available use it to get screen desk_x_count
    if command -v xrandr >/dev/null 2>&1; then
        screen_count=$(xrandr -q | grep -c ' connected')
    fi

    ## Set the wallpaper for each virtual desktop
    for ((x=0; x<desk_x_count; x++)); do
        for ((y=0; y<desk_y_count; y++)); do
            for ((z=0; z<screen_count; z++)); do
                # -desktop-bg-add OPT1 OPT2 OPT3 OPT4 OPT5 Add a desktop bg definition.
                # OPT1 = ContainerNo OPT2 = ZoneNo OPT3 = Desk_x. OPT4 = Desk_y. OPT5 = bg file path
                enlightenment_remote -desktop-bg-add 0 "$z" "$x" "$y" "$OFILE.edj"&
            done
        done
    done

    # Remove all Variety wallpapers, but the current one and the previous one
    #   as we are calling enlightenment_remote asynchronously, if the previous wallpaper hasn't been
    #   replaced yet then the wallpaper will get set back to the theme one causing ugly artifacts
    LAST_WALLPAPER_FILE="$HOME/.config/variety/.enlightenment_last_wallpaper.txt"

    if [ -e "$LAST_WALLPAPER_FILE" ]; then
        find "$OUTPUT_DIR" -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v "$(cat "$LAST_WALLPAPER_FILE")" | xargs rm
    else
        find "$OUTPUT_DIR" -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | xargs rm
    fi
    echo "$OFILE.edj" > "$LAST_WALLPAPER_FILE"
    exit 0
fi

# KDE: Users on KDE 4 or Plasma < 5.7 will have to manually choose ~/Pictures/variety-wallpaper/ as a slideshow folder with a short interval.
# Afterwards, with the command below, Variety will just overwrite the single file there when changing the wallpaper
# and KDE will refresh it
# On Plasma 5.7 and above, the wallpaper choosing is automatic.
if [ "${KDE_FULL_SESSION}" == "true" ]; then
    # Plasma 5.7 introduced a new feature to set the wallpaper via a qdbus script:
    # https://github.com/KDE/plasma-workspace/commit/903cbfd7e267a4812a6ec222eb7e1b5dd775686f
    if [[ -n "${KDE_SESSION_VERSION}" && "${KDE_SESSION_VERSION}" == '5' ]]; then
        
        getdimensions=$( xdpyinfo | grep dimensions | awk '{print $2}' )
        screenwidth=${getdimensions%x*}
        screenheight=${getdimensions#*x}
        wh=$(identify -format "%wx%h" "$WP")
       
       
        #if [[ ${wh#*x} -gt "$screenheight" ]] ; then
        if [[ ${wh%x*} -ne "$screenwidth" ]] || [[ ${wh#*x} -ne "$screenheight" ]] ; then
            mogrify -resize 1920x1080 -background none -gravity center -extent 1920x1080 $WP
        fi
       
    
        
        qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript  "
      
        var allDesktops = desktops();
        for (i=0; i < allDesktops.length; i++) {
            d = allDesktops[i];
            d.wallpaperPlugin = 'org.kde.image';
            d.currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
            d.writeConfig('Image', 'file://""$WP""')
        }
        
       "
    
       
        final=${WP/sourceimages/backgrounds}
        echo "final $final"
        echo "$final" > ""$HOME"/mhsetrootimagefile"
        new=$(cat "$HOME"/mhsetrootimagefile)
        to=${new%/*}
        mkdir -pv "$to"
        mv -v $WP $to
        # Reuse the exit code from qdbus
        exit "$?"
    else
        WALLDIR="$(xdg-user-dir PICTURES)/variety-wallpaper"
        echo $WALLDIR
        mkdir -p "$WALLDIR"
        # Remove all old wallpapers
        rm -fv "${WALLDIR}"/*

        NEWWP="${WALLDIR}/wallpaper-kde-$RANDOM.jpg"
        cp "$WP" "$NEWWP"
        touch "$NEWWP"
    fi
fi

# Cinnamon, for cases when it is detectable
if [ "$XDG_CURRENT_DESKTOP" == "X-Cinnamon" ]; then
    gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
    if [ "$(gsettings get org.cinnamon.background picture-options)" == "'none'" ]; then
        gsettings set org.cinnamon.background picture-options 'zoom'
    fi

    gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
    if [ "$(gsettings get org.cinnamon.desktop.background picture-options)" == "'none'" ]; then
        gsettings set org.cinnamon.desktop.background picture-options 'zoom'
    fi
    exit 0
fi

# Gnome 3, Unity
gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
if [ "$(gsettings get org.gnome.desktop.background picture-options)" == "'none'" ]; then
    gsettings set org.gnome.desktop.background picture-options 'zoom'
fi

# Deepin
if [ "$(gsettings list-schemas | grep -c com.deepin.wrap.gnome.desktop.background)" -ge 1 ]; then
    gsettings set com.deepin.wrap.gnome.desktop.background picture-uri "file://$WP"
    if [ "$(gsettings get com.deepin.wrap.gnome.desktop.background picture-options)" == "'none'" ]; then
        gsettings set com.deepin.wrap.gnome.desktop.background picture-options 'zoom'
    fi
fi

# XFCE
command -v xfconf-query >/dev/null 2>&1
rc=$?
if [[ $rc = 0 ]] ; then
    for i in $(xfconf-query -c xfce4-desktop -p /backdrop -l | grep -E -e "screen.*/monitor.*image-path$" -e "screen.*/monitor.*/last-image$"); do
        xfconf-query -c xfce4-desktop -p "$i" -n -t string -s "" 2> /dev/null
        xfconf-query -c xfce4-desktop -p "$i" -s "" 2> /dev/null
        xfconf-query -c xfce4-desktop -p "$i" -s "$WP" 2> /dev/null
    done
    echo "
    $WP
    $from
    $moveto
    "
    fileis=${WP/from/moveto}
    notify-send "WP" "$WP"
    notify-send "$from" "$moveto"
    echo "from- moreto $from $moveto"
    notify-send "here" "$fileis"
    movewallpaper 
   
 
fi

# LXDE/PCmanFM
if [ "$XDG_CURRENT_DESKTOP" == "LXDE" ]; then
    pcmanfm --set-wallpaper "$WP" 2> /dev/null
fi

# LXQt/PCmanFM-qt
if [ "$XDG_CURRENT_DESKTOP" == "LXQt" ]; then
    pcmanfm-qt --set-wallpaper "$WP" 2> /dev/null
fi

# i3, openbox, dwm: use either feh or nitrogen
if [[ "$XDG_CURRENT_DESKTOP" == "i3"* ]] || [[ "$XDG_SESSION_DESKTOP" == "i3"* ]] ||
        [[ "$DESKTOP_SESSION" == "openbox" ]] || [[ "$XDG_SESSION_DESKTOP" == *"dwm"* ]] ||
        [[ "$XDG_CURRENT_DESKTOP" == *"dwm"* ]]; then
    if command -v "feh" >/dev/null 2>&1; then
        feh --bg-fill "$WP" 2> /dev/null
    elif command -v "nitrogen" >/dev/null 2>&1; then
        nitrogen --set-zoom-fill --save "$WP" 2> /dev/null
    fi
fi

# trinity
if [ "$XDG_CURRENT_DESKTOP" == "Trinity" ]; then
    dcop kdesktop KBackgroundIface setWallpaper "$WP" 4 2> /dev/null
fi

# MATE after 1.6
gsettings set org.mate.background picture-filename "$WP" 2> /dev/null

# MATE before 1.6
mateconftool-2 -t string -s /desktopWP/mate/background/picture_filename "$WP" 2> /dev/null

# Cinnamon after 1.8, before 2.0
gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null

# Cinnamon after 2.0
gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null

# Gnome 2
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$WP" 2> /dev/null

# Awesome Window Manager

# Set the path to the wallpaper using awesome-client, which communicates with awesome using D-Bus.
# Be sure to start variety when you start awesome, such as by adding it to ~/.xinitrc in Arch Linux.

# echo "local gears = require(\"gears\") gears.wallpaper.maximized(\"$1\", s, true)" | awesome-client

# NOTE: This config will change the wallpaper after your current awesome theme sets it.
# As such, the theme's wallpaper will briefly appear before being replaced with variety's wallpaper.


# Show a notification on wallpaper change (only when the change is automatic). Display the original filename, but the post-effects image.
# name=$(echo "$3" | sed 's/\//\n/g'| tail -n 1)
# if [ "$2" == "auto" ]; then notify-send --icon "$WP" "Wallpaper changed" "$name" ; fi

if [[ "$XDG_CURRENT_DESKTOP" == "Fluxbox" ]] ; then
    if command -v "feh" >/dev/null 2>&1; then
        feh --bg-fill "$WP" 2> /dev/null
    elif command -v "nitrogen" >/dev/null 2>&1; then
        #nitrogen --set-zoom-fill --save "$WP" 2> /dev/null
        nitrogen --set-scaled "$WP" 2> /dev/null
        echo "Nitrogen"
        echo "$WP" > $HOME/"/mhsetrootimagefile"
    elif command -v "mh5000" >/dev/null 2>&1; then
        mh5000 -f -S "$WP"
        echo "$WP" > $HOME/"/mhsetrootimagefile"
    fi
fi
 
I just did it long hand instead . I've used substution before in other scripts without issues. it boggles my mind.

Code:
movewallpaper() {
    
    filename=${WP##*/}
    subdir=${WP%/*}
    subdir=${subdir##*/}
    echo $subdir
    
    to=$moveto/$subdir
    if [[ ! -d "$to" ]] ; 
    then
        mkdir -p "$to"
        mv $WP $to
        echo "$to/$filename" > "$HOME"/mhsetrootimagefile
        #notify-send "moved file" "$to/$filename"
    else
        mv $WP $to
        echo "$to/$filename" > "$HOME"/mhsetrootimagefile
        #notify-send "moved file" "$to/$filename"
    fi
     
     
}
 
I just did it long hand instead . I've used substution before in other scripts without issues. it boggles my mind.

Code:
movewallpaper() {
  
    filename=${WP##*/}
    subdir=${WP%/*}
    subdir=${subdir##*/}
    echo $subdir
  
    to=$moveto/$subdir
    if [[ ! -d "$to" ]] ;
    then
        mkdir -p "$to"
        mv $WP $to
        echo "$to/$filename" > "$HOME"/mhsetrootimagefile
        #notify-send "moved file" "$to/$filename"
    else
        mv $WP $to
        echo "$to/$filename" > "$HOME"/mhsetrootimagefile
        #notify-send "moved file" "$to/$filename"
    fi
   
   
}

I'm not commenting on the bash non-sh compatible extensions used before, but apart from the '[[' instead of '[' braces, this bit would work in sh(1).

However the -d test and two branches are unnecessary, when 'mkdir -p' isn't an error if a directory already exists!
 
I'm not commenting on the bash non-sh compatible extensions used before, but apart from the '[[' instead of '[' braces, this bit would work in sh(1).
I'll look into that
However the -d test and two branches are unnecessary, when 'mkdir -p' isn't an error if a directory already exists!
yeah I know ,, I think it's a force of habit check first then issue the command

edit:
it cuts it down some thanks
Code:
movewallpaper() {
    
    filename=${WP##*/}
    subdir=${WP%/*}
    subdir=${subdir##*/}
    to=$moveto/$subdir
    mkdir -p "$to"
    [ -f $WP ] && mv $WP $to ;
    echo "$to/$filename" > "$HOME"/mhsetrootimagefile
    WP=$to/$filename
}
 
Can you provide a single-line example that shows the problem?
I'd have to screw up my script again. but ... let me see what I can do.

I see what it is doing now that I put a count on it, on first pass it doesn't work

Code:
from=/media/storage/wallpaper/backgrounds
moveto=/media/storage/wallpaper/background-storage
mkdir -p "$moveto"

images="$from"

count=0

movewallpaper() {
 
    newDir=${WP/from/moveto}
    newDir=${newDir%/*}
    echo "$((count++)) newDir $newDir"
 
 
 
    filename=${WP##*/}
    subdir=${WP%/*}
    subdir=${subdir##*/}
    to="$moveto/$subdir"
    mkdir -p "$to"
    [ -f "$WP" ] && mv "$WP" "$to" ;
    echo "$to/$filename" > "$HOME"/mhsetrootimagefile
    WP="$to"/"$filename"
}

output
Code:
userx@FBSD13:~$ xfce4-setwallpaper
0 newDir /media/storage/wallpaper/backgrounds/Kaley_Cuoco
1 newDir /media/storage/wallpaper/background-storage/Kaley_Cuoco
2 newDir /media/storage/wallpaper/background-storage/Kaley_Cuoco
3 newDir /media/storage/wallpaper/background-storage/Kaley_Cuoco
 
Sorry if I missunderstand something but this seems overly complicated.
Isn't this the same thing?
Bash:
#!/bin/sh

dbfile="$HOME/Pictures/.background.db"

# while :; do
#
if [ ! -s "${dbfile}" ]; then
    find "$HOME/Pictures" -type f ! -name "${dbfile##*/}" \
        | sort -R > "${dbfile}"
fi

picture=$(head -n 1 "${dbfile}")
# notify ...
sed -I '' 1d "${dbfile}"
feh --bg-max "${picture}"

# sleep 600
# done
 
Sorry if I misunderstand something but this seems overly complicated.
Isn't this the same thing?
Bash:
#!/bin/sh

dbfile="$HOME/Pictures/.background.db"

# while :; do
#
if [ ! -s "${dbfile}" ]; then
    find "$HOME/Pictures" -type f ! -name "${dbfile##*/}" \
        | sort -R > "${dbfile}"
fi

picture=$(head -n 1 "${dbfile}")
# notify ...
sed -I '' 1d "${dbfile}"
feh --bg-max "${picture}"

# sleep 600
# done
I do suppose , only I am running this script on many different Linux distros and freeBSD and it is moving the images to a different location each time to insure i use them all then when source is empty it moves everything back from the different location.

so I need a fresh "copy" of current images on hand that is the reason for the "complicated" scripting. As I have another script to that works in tandem with this one as well which deletes the image when I run that one if I don't like the image after seeing it on my screen then that one calls a the "same" script that does not have a loop in it so it does not start another timed one, so basically it is 3 scripts working together, so more complexity is now at hand.

the so far finished product.
Code:
#!/usr/bin/env bash
#set -x
#set -e
# This script is run by Variety when a new wallpaper is set.
# You can use bash, python or whatever suits you for the script.
# Here you can put custom commands for setting the wallpaper on your specific desktop environment
# or run commands like notify-send to notify you of the change, or you can
# run commands that would theme your browser, login screen or whatever you desire.
#
# PARAMETERS:
# $1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper
# (after effects, clock, etc. are applied).
#
# $2: The second passed parameter is "auto" when the wallpaper is changed automatically (i.e. regular change), "manual"
# when the user has triggered the change or "refresh" when the change is triggered by a change in quotes, clock, etc.
#
# $3: The third passed parameter is the absolute path to the original wallpaper image (before effects, clock, etc.)
#
# EXAMPLE:
# echo "$1" # /home/username/.config/variety/wallpaper/wallpaper-clock-fac0eef772f9b03bd9c0f82a79d72506.jpg
# echo "$2" # auto
# echo "$3" # /home/username/Pictures/Wallpapers/Nature/green-tunnel-1920x1080-wallpaper-861.jpg
#images=/home/userx/Images/wallheaven
#images=/home/userx/Pictures/wallpapers
#from=/media/storage/wallpaper/test-papers

from=/media/storage/wallpaper/backgrounds
moveto=/media/storage/wallpaper/background-storage

#moveto=/media/storage/wallpaper/test-background-storage
 
images="$from"

getfile () {
   
    WP=${image[$RANDOM % ${#image[@]} ]}
    echo "error"
    echo $?
    exitCode=$?
   
}

movewallpaper() {
  
    filename=${WP##*/}
    subdir=${WP%/*}
    subdir=${subdir##*/}
    to="$moveto/$subdir"
    mkdir -p "$to"
    [ -f "$WP" ] && mv "$WP" "$to" ;
    echo "$to/$filename" > "$HOME"/mhsetrootimagefile
    WP="$to"/"$filename"
    notify-send "Auto Paper" "$WP"
   
  
}

#run it every x amount of elapped time

while [[ true ]]
do


#source images directory
empty=$(find "$from" \( -type f -name "*.jpg" -o -type f -name "*.png" \) | wc -l)
echo "empty $empty"
 notify-send "empty" "$empty"
#check storage place if empty
#then move holding place back to storage place
case $empty in
    0)
        holdingimg=$(find "$moveto" \( -type f -name "*.jpg" -o -type f -name "*.png" \) | wc -l)
        if [[ $holdingimg -gt '0' ]] ; then
            notify-send  "empty::$empty Images moved to" "$holdingimg"
            while read f
            do
                filename=${f##*/}
                subdir=${f%/*}
                subdir=${subdir##*/}
                echo $subdir
                to=$from/$subdir
                mkdir -p "$to"
                 [[ -f $f ]] && { mv $f $to ; echo "$to/$filename" > "$HOME"/mhsetrootimagefile ; }
           
            done < <(find "$moveto" \( -type f -iname "*.jpg" -o -type f -iname "*.png" \) )
        elif [[ $holdingimg -le '0' ]] ; then
            notify-send " no images to be found in $favimages
            or
            $holding
            exiting ..."
             exit
        fi
        ;;
    1)
        #img=$images/$(ls $images)
        ;;
esac
#put list in bash array named images
mapfile -t image < <(find "$images" \( -type f -name "*.jpg" -o -type f -name "*.png" \))

# Here you may apply some additional custom operations on the wallpaper before it is applied.
# In the end put the path to the actual final wallpaper image file in the WP variable.
# The default is to simply set WP=$1.

getfile

notify-send "current image is" "$WP"

# Enlightenment
# Needs Modules/System/DBus Extension loaded to work
if [[ "$DESKTOP" == *"Enlightenment"* ]] || [[ "$DESKTOP" == *"Moksha"* ]]; then

    OUTPUT_DIR="$HOME/.e/e/backgrounds"

    TEMPLATE='
    images { image: "@IMAGE@" USER; }
    collections {
      group {
      name: "e/desktop/background";
      data { item: "style" "4"; item: "noanimation" "1"; }
      max: @WIDTH@ @HEIGHT@;
      parts {
        part {
        name: "bg";
        mouse_events: 0;
        description {
          state: "default" 0.0;
          aspect: @ASPECT@ @ASPECT@;
          aspect_preference: NONE;
          image { normal: "@IMAGE@"; scale_hint: STATIC; }
        }
        }
      }
      }
    }
    '

    OFILE="$OUTPUT_DIR/variety_wallpaper_$RANDOM"

    DIMENSION="$(identify -format "%w/%h" "$WP")"

    if [ ! -z "$DIMENSION" ]; then
        WIDTH="$(echo "$DIMENSION" | cut -d/ -f1)"
        HEIGHT="$(echo "$DIMENSION" | cut -d/ -f2)"
        IMAGE="$(echo "$WP" | sed 's/[^[:alnum:]_-]/\\&/g')"

        if [ -z "$HEIGHT" ] || [ "$HEIGHT" = "0" ]; then
            ASPECT="0.0"
            echo "$WP" > $HOME/"/mhsetrootimagefile"
        else
            ASPECT="$(echo "scale=9; $DIMENSION" | bc)"
            echo "$WP" > $HOME/"/mhsetrootimagefile"
        fi
    fi

    printf "%s" "$TEMPLATE" | \
    sed "s/@ASPECT@/$ASPECT/g; s/@WIDTH@/$WIDTH/g; s/@HEIGHT@/$HEIGHT/g; s|@IMAGE@|$IMAGE|g" > "$OFILE.edc"
    edje_cc "$OFILE.edc" "$OFILE.edj" 2>/dev/null
    rm "$OFILE.edc"

    ## Get the current number of virtual desktops
    desk_x_count=$(enlightenment_remote -desktops-get | awk '{print $1}')
    desk_y_count=$(enlightenment_remote -desktops-get | awk '{print $2}')

    ## Get the current number of screens
    screen_count=1
    # If xrandr is available use it to get screen desk_x_count
    if command -v xrandr >/dev/null 2>&1; then
        screen_count=$(xrandr -q | grep -c ' connected')
    fi

    ## Set the wallpaper for each virtual desktop
    for ((x=0; x<desk_x_count; x++)); do
        for ((y=0; y<desk_y_count; y++)); do
            for ((z=0; z<screen_count; z++)); do
                # -desktop-bg-add OPT1 OPT2 OPT3 OPT4 OPT5 Add a desktop bg definition.
                # OPT1 = ContainerNo OPT2 = ZoneNo OPT3 = Desk_x. OPT4 = Desk_y. OPT5 = bg file path
                enlightenment_remote -desktop-bg-add 0 "$z" "$x" "$y" "$OFILE.edj"&
            done
        done
    done

    # Remove all Variety wallpapers, but the current one and the previous one
    #   as we are calling enlightenment_remote asynchronously, if the previous wallpaper hasn't been
    #   replaced yet then the wallpaper will get set back to the theme one causing ugly artifacts
    LAST_WALLPAPER_FILE="$HOME/.config/variety/.enlightenment_last_wallpaper.txt"

    if [ -e "$LAST_WALLPAPER_FILE" ]; then
        find "$OUTPUT_DIR" -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v "$(cat "$LAST_WALLPAPER_FILE")" | xargs rm
    else
        find "$OUTPUT_DIR" -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | xargs rm
    fi
    echo "$OFILE.edj" > "$LAST_WALLPAPER_FILE"
    exit 0
fi

# KDE: Users on KDE 4 or Plasma < 5.7 will have to manually choose ~/Pictures/variety-wallpaper/ as a slideshow folder with a short interval.
# Afterwards, with the command below, Variety will just overwrite the single file there when changing the wallpaper
# and KDE will refresh it
# On Plasma 5.7 and above, the wallpaper choosing is automatic.
if [ "${KDE_FULL_SESSION}" == "true" ]; then
    # Plasma 5.7 introduced a new feature to set the wallpaper via a qdbus script:
    # https://github.com/KDE/plasma-workspace/commit/903cbfd7e267a4812a6ec222eb7e1b5dd775686f
    if [[ -n "${KDE_SESSION_VERSION}" && "${KDE_SESSION_VERSION}" == '5' ]]; then
       
        getdimensions=$( xdpyinfo | grep dimensions | awk '{print $2}' )
        screenwidth=${getdimensions%x*}
        screenheight=${getdimensions#*x}
        wh=$(identify -format "%wx%h" "$WP")
      
      
        #if [[ ${wh#*x} -gt "$screenheight" ]] ; then
        if [[ ${wh%x*} -ne "$screenwidth" ]] || [[ ${wh#*x} -ne "$screenheight" ]] ; then
            mogrify -resize 1920x1080 -background none -gravity center -extent 1920x1080 $WP
        fi
      
   
       
        qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript  "
     
        var allDesktops = desktops();
        for (i=0; i < allDesktops.length; i++) {
            d = allDesktops[i];
            d.wallpaperPlugin = 'org.kde.image';
            d.currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
            d.writeConfig('Image', 'file://""$WP""')
        }
       
       "
   
      
       movewallpaper
        # Reuse the exit code from qdbus
        exit "$?"
    else
        WALLDIR="$(xdg-user-dir PICTURES)/variety-wallpaper"
        echo $WALLDIR
        mkdir -p "$WALLDIR"
        # Remove all old wallpapers
        rm -fv "${WALLDIR}"/*

        NEWWP="${WALLDIR}/wallpaper-kde-$RANDOM.jpg"
        cp "$WP" "$NEWWP"
        touch "$NEWWP"
    fi
fi

# Cinnamon, for cases when it is detectable
if [ "$XDG_CURRENT_DESKTOP" == "X-Cinnamon" ]; then
    gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
    if [ "$(gsettings get org.cinnamon.background picture-options)" == "'none'" ]; then
        gsettings set org.cinnamon.background picture-options 'zoom'
    fi

    gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
    if [ "$(gsettings get org.cinnamon.desktop.background picture-options)" == "'none'" ]; then
        gsettings set org.cinnamon.desktop.background picture-options 'zoom'
    fi
    exit 0
fi

# Gnome 3, Unity
gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
if [ "$(gsettings get org.gnome.desktop.background picture-options)" == "'none'" ]; then
    gsettings set org.gnome.desktop.background picture-options 'zoom'
fi

# Deepin
if [ "$(gsettings list-schemas | grep -c com.deepin.wrap.gnome.desktop.background)" -ge 1 ]; then
    gsettings set com.deepin.wrap.gnome.desktop.background picture-uri "file://$WP"
    if [ "$(gsettings get com.deepin.wrap.gnome.desktop.background picture-options)" == "'none'" ]; then
        gsettings set com.deepin.wrap.gnome.desktop.background picture-options 'zoom'
    fi
fi

# XFCE
command -v xfconf-query >/dev/null 2>&1
rc=$?
if [[ $rc = 0 ]] ; then
    for i in $(xfconf-query -c xfce4-desktop -p /backdrop -l | grep -E -e "screen.*/monitor.*image-path$" -e "screen.*/monitor.*/last-image$"); do
        xfconf-query -c xfce4-desktop -p "$i" -n -t string -s "" 2> /dev/null
        xfconf-query -c xfce4-desktop -p "$i" -s "" 2> /dev/null
        xfconf-query -c xfce4-desktop -p "$i" -s "$WP" 2> /dev/null
    done
    movewallpaper
  
 
fi

# LXDE/PCmanFM
if [ "$XDG_CURRENT_DESKTOP" == "LXDE" ]; then
    movewallpaper
    pcmanfm --set-wallpaper "$WP" 2> /dev/null
fi

# LXQt/PCmanFM-qt
if [ "$XDG_CURRENT_DESKTOP" == "LXQt" ]; then
    movewallpaper
    pcmanfm-qt --set-wallpaper "$WP" 2> /dev/null
  
fi

# i3, openbox, dwm: use either feh or nitrogen
if [[ "$XDG_CURRENT_DESKTOP" == "i3"* ]] || [[ "$XDG_SESSION_DESKTOP" == "i3"* ]] ||
        [[ "$DESKTOP_SESSION" == "openbox" ]] || [[ "$XDG_SESSION_DESKTOP" == *"dwm"* ]] ||
        [[ "$XDG_CURRENT_DESKTOP" == *"dwm"* ]]; then
    if command -v "feh" >/dev/null 2>&1; then
        movewallpaper
        feh --bg-fill "$WP" 2> /dev/null
      
    elif command -v "nitrogen" >/dev/null 2>&1; then
        movewallpaper
        nitrogen --set-zoom-fill --save "$WP" 2> /dev/null
    fi
fi

# trinity
if [ "$XDG_CURRENT_DESKTOP" == "Trinity" ]; then
    dcop kdesktop KBackgroundIface setWallpaper "$WP" 4 2> /dev/null
    movewallpaper
fi

# MATE after 1.6
if command -v "gsettings" >/dev/null 2>&1; then
movewallpaper
gsettings set org.mate.background picture-filename "$WP" 2> /dev/null

fi

# MATE before 1.6
 
 
mateconftool-2 -t string -s /desktopWP/mate/background/picture_filename "$WP" 2> /dev/null

 
# Cinnamon after 1.8, before 2.0
if command -v "gsettings" >/dev/null 2>&1; then
gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null

fi

# Cinnamon after 2.0
if command -v "gsettings" >/dev/null 2>&1; then
movewallpaper
gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null

fi
# Gnome 2
 
 
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$WP" 2> /dev/null

 

# Awesome Window Manager

# Set the path to the wallpaper using awesome-client, which communicates with awesome using D-Bus.
# Be sure to start variety when you start awesome, such as by adding it to ~/.xinitrc in Arch Linux.

# echo "local gears = require(\"gears\") gears.wallpaper.maximized(\"$1\", s, true)" | awesome-client

# NOTE: This config will change the wallpaper after your current awesome theme sets it.
# As such, the theme's wallpaper will briefly appear before being replaced with variety's wallpaper.


# Show a notification on wallpaper change (only when the change is automatic). Display the original filename, but the post-effects image.
# name=$(echo "$3" | sed 's/\//\n/g'| tail -n 1)
# if [ "$2" == "auto" ]; then notify-send --icon "$WP" "Wallpaper changed" "$name" ; fi

if [[ "$XDG_CURRENT_DESKTOP" == "Fluxbox" ]] ; then
    if command -v "feh" >/dev/null 2>&1; then
        movewallpaper
        feh --bg-fill "$WP" 2> /dev/null
      
    elif command -v "nitrogen" >/dev/null 2>&1; then
        #nitrogen --set-zoom-fill --save "$WP" 2> /dev/null
        movewallpaper
        nitrogen --set-scaled "$WP" 2> /dev/null
      
      
    elif command -v "mh5000" >/dev/null 2>&1; then
        movewallpaper
        mh5000 -f -S "$WP"
      
    fi
fi

sleep $((60*3))
 
done
 
Back
Top