【问题标题】:Icon changing Script图标更改脚本
【发布时间】:2014-07-04 13:28:41
【问题描述】:

我无法让这个程序处理带有空格的文件。 即使我修改它以使代码在每个空格之前都有“\”,它也会不断出错

发生的事情是我在网上找到了这段代码,当你发送信息并且文件没有空格时,它作为一个 shell 脚本工作,现在我正试图让它在 automator 和任何文件中工作

iconSource="$1"
iconDestination="$2"
newiconSource="${iconSource}"
newiconDestination="${iconDestination}"
echo $newiconSource
echo $newiconDestination
icon=/tmp/`basename $newiconSource`
rsrc=/tmp/icon.rsrc

# Create icon from the iconSource
cp $newiconSource $icon

# Add icon to image file, meaning use itself as the icon
sips -i $icon

# Take that icon and put it into a rsrc file
DeRez -only icns $icon > $rsrc

# Apply the rsrc file to
SetFile -a C $newiconDestination

if [ -f $newiconDestination ]; then
# Destination is a file
Rez -append $rsrc -o $newiconDestination
elif [ -d $newiconDestination ]; then
# Destination is a directory
# Create the magical Icon\r file
touch $newiconDestination/$'Icon\r'
Rez -append $rsrc -o $newiconDestination/Icon?
SetFile -a V $newiconDestination/Icon?
fi

【问题讨论】:

    标签: bash directory icons automator


    【解决方案1】:

    这里有一段更简单的代码可以重现您的问题:

    file="hello world"
    rm $file
    

    这个输出:

    rm: cannot remove `hello': No such file or directory
    rm: cannot remove `world': No such file or directory
    

    (如果没有,它只是删除了您名为“hello”和“world”的文件。对此感到抱歉。)

    要修复它,您必须将所有对变量的引用都用双引号引起来,以防止出现通配符和分词:

    file="hello world"
    rm "$file"  # <- Note double quotes
    

    ShellCheck 自动指出这一点。通过它运行你的脚本,它会指出大部分需要引用的引用。

    【讨论】:

    • 我尝试添加 qouotws 还是不行
    • 确保数据中的空格前面没有反斜杠
    • 我也检查过
    • 是的,但这是因为我把报价放在了错误的位置。谢谢谢谢谢谢!
    猜你喜欢
    • 2012-05-18
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多