Your question doesn't specify very well what you have got, or why you need to do it in bash
, but if you must do it that way, you can do it like this:
#!/bin/bash
VERSION=2.12
cat > foo.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildAliasOf</key>
<string>ProEditor</string>
<key>BuildVersion</key>
<value>$VERSION</value>
</dict>
</plist>
EOF
So, you save this in a file called Buildplist
and then do this to make it executable
chmod +x Buildplist
and then you run it by typing this:
./Buildplist
You can make it write the plist file directly into /Library/launchAgents
by changing the second line to something like this:
cat > /Library/launchAgents/yourApp/yourApp.plist <<EOF
You can make it accept parameters too. So if you want to pass the Author as the first parameter, you can do it like this:
#!/bin/bash
VERSION=2.12
AUTHOR="$1"
cat > foo.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildAliasOf</key>
<string>ProEditor</string>
<key>BuildVersion</key>
<value>$VERSION</value>
<author>$AUTHOR</author>
</dict>
</plist>
EOF
and then run
./Buildplist "Freddy Frog"
to pass "Freddy Frog" as the author.
If you want to avoid overwriting any plist file that already exists, you can do it like this:
#!/bin/bash
PLISTFILE="/Library/launchAgents/yourApp/yourApp.plist"
# If plist already exists, do not overwrite, just exit quietly
[ -f "$PLISTFILE" ] && exit
cat > "$PLISTFILE" <<EOF
...
...
EOF
I put the name of the plist file in a variable to simplify maintenance, and avoid typing it twice.
bash
, why can't you use an editor? – Rebba