[risolto] bash(wallpaper): printf che non funziona

Salve, mi sto scrivendo un piccolo tool per cambiare lo sfondo del desktop,
selezionando l’immagine da vari server (bing.com, Nat. Geo., NASA ecc. ecc).
c’è una printf che mi sta facendo impazzire.
devo salvare in un variabile il mese sezionato casualmente in base all’anno,
anch’esso selezionato casualmente.

function provider_natgeo()
{
	local __wall=$1
	local NG_URL="https://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery."
	local url
	local year
	local ng_yourShot
	local month
	local json_strings
	local jqcmd
	declare -i year
	declare -i ty=$(date +%Y)
	declare -r -i epoch=2009
	declare -i json_max_elements
	declare -i json_idx=0

	year=$(shuf -n1 -i$epoch-$ty)
	printf -v month "%02d" $( $ty -ne $year ] && "$(shuf -n1 -i1-12)" || "$(shuf -n1 -i1-$(date +%m))")
#                              +++++++++++++++++++----------------------------------------------------------
#                              fin qui ok.         da qui in poi no err: "bash: X comando non trovato
#                                                  dove X è il mese

# se invece uso un if, funziona.
echo $month
exit
#	if  $ty -eq $year ]
#	then
#		printf -v month "%02d" $(shuf -n1 -i1-$(date +%m))
#	else
#		printf -v month "%02d" $(shuf -n1 -i1-12)
#	fi
	json_strings=$(curl -s $NG_URL$year-$month.json | jq .items)
	json_max_elements=$(echo $json_strings | jq '. | length')
	json_idx=$(shuf -i0-$json_max_elements -n1)
	ng_yourShot=$(echo $json_strings | jq .$json_idx].yourShot)
	printf -v url "%s" $(echo $json_strings | jq .$json_idx].url)
	if  "$ng_yourShot" = "true" ]
	then
		printf -v jqcmd ".%d].sizes\"1600\"]" $json_idx
		printf -v url "%s%s" $url $(echo $json_strings | jq $jqcmd)
	fi

	eval $__wall="$url"
}

wallpaper=""
provider_natgeo wallpaper

printf "%s\n" $wallpaper

[quote=romulus]
…]

printf -v month "%02d" $( $ty -ne $year ] && "$(shuf -n1 -i1-12)" || "$(shuf -n1 -i1-$(date +%m))") [/quote]

Credo tu debba inviargli i risultati nel parametro con echo:

	printf -v month "%02d" $( $ty -ne $year ] && echo "$(shuf -n1 -i1-12)" || echo "$(shuf -n1 -i1-$(date +%m))")

[quote=vinlinux][quote=romulus]
…]

printf -v month "%02d" $( $ty -ne $year ] && "$(shuf -n1 -i1-12)" || "$(shuf -n1 -i1-$(date +%m))") [/quote]

Credo tu debba inviargli i risultati nel parametro con echo:

printf -v month "%02d" $( $ty -ne $year ] && echo "$(shuf -n1 -i1-12)" || echo "$(shuf -n1 -i1-$(date +%m))") [/quote]

Ottima intuizione, interpretavo male il costrutto:

  condizione ] && istruzione || istruzione 

insieme a:

 $(comando -opt arg)

adesso così funziona

printf -v month "%02d" $( $ty -ne $year ] && shuf -n1 -i1-12 || shuf -n1 -i1-$(date +%m))

grazie

PS
ci vorrebbe una spiegazione migliore, ma… al momento non mi viene niente di meglio.