Custom zsh script failing on startup

I’m using a zsh script to start conky and download and update wallpaper using wget and variety respectively. For some reason it is crashing on startup. It has a while loop.
The whole setup I’m using can be found here. It includes a startup script (which launches two other zsh scripts and is launched using an autostart.desktop file), a downloader script and an updater script (this one is failing).
This is the script in question. (edited to remove reference to some directories, may not work as it is below, but I’ve confirmed that it works when I run it from command line or Alt+F2)

#!/bin/zsh

cd $HOME/Pictures/Wallpapers
declare -i LAST
let LAST=0
declare -i LAST_TIME
let LAST_TIME=0
declare -i NEW_TIME
let NEW_TIME=1

while [ 1 ]; do
	case "$(nmcli -g connectivity general)" in
    full) 
   		#echo "HTTP connectivity is up"
    	if (( LAST == 1 ))
    	then
			NEW_TIME=$(stat -c %Y world_sunlight_map_rectangular.jpg)
			if (( LAST_TIME == NEW_TIME ))	
			then
				sleep 1
				let LAST=1
			else
				let LAST=0
			fi
    	else  
			#echo "Seting wallpaper"
			variety --set=world_sunlight_map_rectangular.jpg
			LAST_TIME=$(stat -c %Y world_sunlight_map_rectangular.jpg)
    	   	sleep 1
    	   	let LAST=1
       	fi
	;;
	limited) 			
	#echo "Limited connectivity"
		if (( LAST == 2 ))
		then
			sleep 1
		else
			#echo "Seting wallpaper"
			variety --set=Sid@Home-Err.png
			sleep 1
			let LAST=2 
		fi
	;;
	none) 
		#echo "The network is down or very slow"
		if (( LAST == 3 ))
		then
			sleep 1
		else
			#echo "Seting wallpaper"
			variety --set=Sid@Home-NoErr.png
			sleep 1
			let LAST=3
		fi
	;;
	esac
done

It runs once and then stops running. I think possible problems may be with autostart script (included below, edited to remove directory reference), or it may not be. Please help!

[Desktop Entry]
Type=Application
Name=Conky
Exec=$HOME/bin/conky.zsh
StartupNotify=false
Terminal=false
Icon=conky-logomark-violet
Categories=System;Monitor;

Any updates on this, guys? I’m sick of starting that script again and again manually.

Well, I’m not sure if this is helpful, but

  • you could use /usr/bin/zsh in the shebang
  • Is there a reason why you declare and let your variables instead of just setting them?
  • why [ 1 ] instead of true?
  • Are you using harcoded path instead of $HOME in the actual script and desktop file? If not, maybe you should? You could also just place the script in your /usr/local/bin and make sure that is in your $PATH

If it runs only once, something is breaking the loop.

I had to reinstall my OS for an unrelated reason and the script got fixed automatically.

@Chrysostomus thanks for your suggestions though. Maybe will be useful to others as part of some zsh troubleshooting steps.

There’s an update. Even a script as easy as the following is not working:

#!/bin/zsh
while [true]; do
	echo "Hello"
done

I also tried following

#!/bin/zsh
while [1]; do
	echo "Hello"
done

I do not understand what’s happening here. I get the following error:

test.zsh:2: no matches found: [1]

It would be

#!/bin/zsh
while true ; do
  echo "Hello"
done

or

#!/bin/zsh
while : ; do
  echo "Hello"
done

The square brackets are only for the test commando.

if test $a -eq $b

is the same as

if [ $a -eq $b ]

1 Like

Yeah, that worked but the problem is back again (not because of this fix). I celebrated too early here.

Finally!
Fixed it by doing troubleshooting with zsh -x, and running the application in the terminal from the desktop file (set Terminal=true).
The problem was with variety and conky commands. They are supposed to return the control to the terminal usually but if they encounter an error then the script just stops.
Fix was to add & at the end of commands like variety and conky.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.