嘗試在 bash 中乘以浮點數不起作用

嘗試在 bash 中乘以浮點數不起作用

我有這個腳本可以將圖像重新縮放為百分比值

#!/bin/bash

percent=$1
echo $percent


for img in `find *.png`;
do
  echo Processing file $img
  width=$( mdls $img  | grep kMDItemPixelWidth | tail -n1 | cut -d= -f2 )
  height=$( mdls $img | grep kMDItemPixelHeight | tail -n1 | cut -d= -f2 )

  newWidth=$((width*percent))
  newHeight=$((height*percent))
  echo $newWidth $newHeight
  sips -z $newWidth $newHeight $img
done

我的 bash 配置為接受逗號作為小數點分隔符號。

所以,為什麼我會輸入

rescale 0,3019

我正在嘗試將圖像重新縮放為其值的 30.19%

問題是該行

  echo $newWidth $newHeight

顯示了乘以 3019 後的值。

echo $percent

顯示 0,3019 (正確的值)

我缺什麼?

答案1

就你的標題而言:bash 只能進行整數相乘。

相關內容