Manually editing the file
Note that you can also always just go into the Terminal and write:
mkdir -p ~/.MacOSX
touch ~/.MacOSX/environment.plist
open ~/.MacOSX/environment.plist
and edit the file accordingly, if that's what you are trying to do. You should preferably use Apple's own Property List Editor.app, which comes with Xcode 3. Surely there are other editors with support for plist files, but I can't recall any right now.
If you want, you can also just open ~/.MacOSX/ and then open the plist file with any other text editor, as long as you keep the right format.
With a shell script
But, in your question you asked for something like that:
#!/usr/bin/env bash
FILE=~/.MacOSX/environment.plist
PLIST=/usr/libexec/PlistBuddy
# if the file doesn't exist, try to create folder
if [ ! -f $FILE ]
then
mkdir -p ~/.MacOSX
fi
# then just add entries (file will be created if it doesn't exist)
$PLIST -c "Add :Variable1 string 'Value1'" $FILE
$PLIST -c "Add :Variable2 string 'Value2'" $FILE
This script will create the file if it doesn't exist already and then add two variables to it. Their names are Variable1 and Variable2, respectively, and their values are Value1 and Value2.
If the file already exists, the variables and values are just appended.
Copy this code, paste it to a file named, for example, script.sh. Save it to your home folder. Open the Terminal, then run
chmod +x script.sh
Now you can run it with ./script.sh and it will create the environment.plist file.
If you want to remove the plist file again, just enter
rm ~/.MacOSX/environment.plist
The folder will remain, but that's not really a problem.