Ash: : unknown operand


I'm using this coding in .profile:

NC='\033[0m' # No Color

echo "Software status report:"
[ printf "$(<$upgradeCheckFile)" = '1' ] \
&& echo -e "${YELLOW}--> Upgrades are available.${NC}\n----> List available upgrades: opkg-upgrade -l\n----> Upgrade packages: opkg-upgrade\n" \
|| echo -e "${GREEN}--> No upgrades available.${NC}\n"

However I get this error ash: : unknown operand when debugging it:

+ upgradeCheckFile=/tmp/opkg-upgrade-check
+ YELLOW='\033[1;33m'
+ GREEN='\033[0;32m'
+ NC='\033[0m'
+ echo 'Software status report:'
Software status report:
+ '[' printf  '=' 1 ]
ash: : unknown operand
+ echo -e '\033[0;32m--> No upgrades available.\033[0m\n'
--> No upgrades available.

The content of /tmp/opkg-upgrade-check is either
or nothing.

Can you please advise how to fix it?

Maybe to save you trouble later…

Upgrading packages (via the CLI opkg upgrade command or the LuCI Upgrade... button) can result in major problems. It is generally highly discouraged, unless you know what you are doing or if there is specific instruction to do so.

This is not about opkg upgrade.
I'm aware of the potential risk, and therefore I'm using this solution.

Sorry to say that, but this is just a wrapper script for opkg upgrade.
Why not using auc?

I know that the error is not directly related. What I’m suggesting is that you don’t try to do this script in the first place since it may get you into serious trouble at some point. But if you’re comfortable with the risk, more power to you.

This (wrapper) script is performing an installation of any package identified for upgrade sequentially.
This means there's no command opkg upgrade to be executed or any other bulk upgrade.

Good idea or not beyond my skill level but have fought with ash a bit.

You have four problems:

  • Ash and bash don't handle $(<file) the same.
  • Ash does not support "cmd" in test. ( not sure what does )
  • test with un-quoted input is bad luck -- empty will error.
  • missing file will error.
root@OpenWrt:/tmp# printf "$(<stuff)\n"

root@OpenWrt:/tmp# printf "$(cat <stuff)\n"
root@OpenWrt:/tmp# [ echo 1 = '1' ] && echo hi
ash: 1: unknown operand
root@OpenWrt:/tmp# [ "$(printf $(cat <stuff))" = '1' ] && echo hi

Not sure what good the printf is doing without a format. None of above work with file missing, would try like this:

root@OpenWrt:/tmp# [ -n stuff -a "$(cat <stuff)" = "1" ] && echo hi

Update: Hmm "<" with cat is redundant too.

I think you may be splitting hairs here... the point of the script is to upgrade packages and it seems that it does it automatically (on a schedule) when there available upgrades. Yes, it uses the install command rather than upgrade, but the net effect may be the same.

I just wanted to make sure you know that upgrading packages can, in some cases, cause major headaches. But it seems you are aware of that already and since you seem fairly confident that this particular script/method is not going to cause issues with your setup, arguing semantics here is probably not useful.


I used another logic in the meantime, means I'm not writing 1 (or 0) in a file, but I write (or delete) a file.
The if-condition is then simply checking for this file.