shell 如何去掉字符串两边的单引号

mpbci0fu  于 2023-03-19  发布在  Shell
关注(0)|答案(1)|浏览(208)

我有一个zsh脚本。有一个函数...

imgPrep()
{
local inFilePath=$1
local outFilePath=$2
local cropHeight=$3
local resize=$4
shift; shift; shift; shift
local options=$@

convert ${inFilePath} -crop 0x${cropHeight}+0+0 +repage -resize ${resize}% ${options} ${outFilePath}
}

我这样调用这个函数:

IMoptions="-despeckle -unsharp 0x3+1+0"
imgPrep ${inputImgFilePath} ${headerImgFilePath} ${headerHeight} ${scale} ${IMoptions}

convert命令失败,可能是因为单引号不应该出现。

convert somefile.jpg -crop 0x60+0+0 +repage -resize 410% '-despeckle -unsharp 0x3+1+0' output.tif

convert: unrecognized option `-despeckle -unsharp 0x3+1+0' @ error/convert.c/ConvertImageCommand/1437

请问我该怎么修?

llmtgqce

llmtgqce1#

我通过使用阵列解决了此问题

local options=("$@") # Store options in an array

convert ${inFilePath} -crop 0x${cropHeight}+0+0 +repage -resize ${resize}% "${options[@]}" ${outFilePath}

...

imgPrep ${inputImgFilePath} ${headerImgFilePath} ${headerHeight} ${scale} "${IMoptions[@]}"

谢谢丹尼尔·凯利提供了正确答案,幸运的是,我在它被删除之前抓住了它,这真是太遗憾了。

相关问题