我有一个小的 bash 脚本,它可以进行简单的文件修改,我想重写代码以提高可读性。我的目标是将命令作为字符串传递给在目录中循环命令的函数。
我尝试使用不同的方法来逃避“$”或不同的“””组合,但没有一个真正起作用。
#!/bin/bash
process="/Users/Gernot/Tools/.Process"
output="/Users/Gernot/Tools/2 Output"
input="/Users/Gernot/Tools/1 Input/"
function run {
for file in "$input$1"/*
do
echo "running procedure $1" #echoes which procedure is running
$2 #does the command for every file in the directory
done
}
run "PDF Komprimieren" "magick convert \$file -density 110 -compress jpeg -quality 100 \$file"
这是我得到的错误:
running procedure PDF Komprimieren
convert: unable to open image '$file': No such file or directory @ error/blob.c/OpenBlob/3497.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/556.
convert: no images defined `$file' @ error/convert.c/ConvertImageCommand/3273.