我有一部分脚本如下。
notify() {
printf -v "old_notif" "%d" "$notif_$2"
now=$(date +%s)
fark=$((now - old_notif))
echo $old_notif
if [ -z $old_notif ]; then
Run Code Online (Sandbox Code Playgroud)
.....
x1=$(date +%s)
export "notif_$2=$x1"
Run Code Online (Sandbox Code Playgroud)
我用 2 个参数调用通知。
notify xyz klm
Run Code Online (Sandbox Code Playgroud)
我在导出函数中创建了一个动态变量。主脚本在while循环中。我的问题是如何使用notif_$2变量if检查?或者如何将它的十进制内容分配给另一个变量?在我尝试使用的示例中,printf它没有分配内容。
bash ×1