简体   繁体   中英

Simple Mac Bash Script (Find/Replace)

First, any support and help on this is largely appreciated.

I'm trying to write a simple Bash script (completely new to this) to replace a file in a given directory.

Basically, I need to write a script to replace the safari preference file, here's what I have..and what's not working for that matter:

#!/bin/bash
find /Files/ -iname "com.apple.Safari.plist" - print0 | xargs -I{} -0 -1 cp file /Users/{}/Library/Preferences

It errors out with the following:

find: -: unknown option
xargs: illegal option -- 1

Any thoughts, ideas, are greatly appreciated.

Thanks,

I couldn't understand what exactly you want to accomplish with this. As I understand, you would have this "com.apple.Safari.plist" in /Files/, is that correct?

And then you want to get this file into some place that, I assume, overwrites Safari's current plist file. Assuming you take ghostdog74's correct advice and remove the space between - print0 , thus turning it into -print0 , and then remove the -1 from xargs, as it doesn't exist, this is what would happen:

find would find your file in /Files/, and xargs would run this: cp file /Users/com.apple.Safari.plist/Library/Preferences ; It would then die, since it would not find a file called "file" or a directory named "/Users/com.apple.Safari.plist/".

That's most likely not what you want. :)

If you just want to copy the file to somewhere, why don't you just do cp /Files/com.apple.Safari.plist ~/Library/Preferences/ ?

Do you really need find and xargs in this case? Could you clarify?

No space between - print0 . and since -1 is not an option, remove it and see.

find /Files/ -iname "com.apple.Safari.plist" -print0 | xargs -I{} -0 cp file /Users/{}/Library/Preferences

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM