Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用带有空格的文件名转义变量_Bash_Pngcrush - Fatal编程技术网

Bash 使用带有空格的文件名转义变量

Bash 使用带有空格的文件名转义变量,bash,pngcrush,Bash,Pngcrush,我正在使用此行批处理我的pngcrush,但我的文件包含空格,这些空格被逐字放入$line,使它们被跳过,因为它们不是有效路径: ls *.png | while read line; do pngcrush -brute $line compressed/$line; done 如何使$line变成这样的转义文件名Button-Users.png将替换为Button\-\Users.png?只需将变量括在双引号中即可。这是一个很好的实践: ls *.png | while read line

我正在使用此行批处理我的
pngcrush
,但我的文件包含空格,这些空格被逐字放入
$line
,使它们被跳过,因为它们不是有效路径:

ls *.png | while read line; do pngcrush -brute $line compressed/$line; done

如何使$line变成这样的转义文件名
Button-Users.png
将替换为
Button\-\Users.png

只需将变量括在双引号中即可。这是一个很好的实践:

ls *.png | while read line; do pngcrush -brute "$line" "compressed/$line"; done

只需将变量用双引号括起来。这是一个很好的实践:

ls *.png | while read line; do pngcrush -brute "$line" "compressed/$line"; done
。在此处使用
for
循环

for f in *.png; do
    pngcrush -brute "$line" compressed/"$line"
done
。在此处使用
for
循环

for f in *.png; do
    pngcrush -brute "$line" compressed/"$line"
done