|Oct 12, 2008, 10:49 PM||#1|
Append text to file with shell script
I have a script that gathers data and will add it to a text file, without overwriting the current text.
I can't quite get it to work properly.
I've tried printing directly, but all this does is overwrite the existing text.
echo $output >> disk_space.txt
I've also tried using VI to edit the file, but I can't get that working either.
vi $file <<EOF :$ $ o $output ESC :w :x EOF
|Oct 13, 2008, 01:20 AM||#2|
Your script should indeed append to disk_space.txt, not overwrite it, and I've never see it fail to work as specified. Perhaps there's another problem. For example, perhaps disk_space.txt already exists and does not have write permission so you can't modify it. Or perhaps you are running this command while the script is cd'ed to another location, so it's writing to /somewhere_else/disk_space.txt. You might change it to an absolute path.
What kind of value is in $output? If it might contain punctuation characters, you'd be safer to put double quotes around it. In fact, I'd recommend doing that in any case.
With my suggestions:
echo "$output" >> /Users/myname/Desktop/disk_space.txt
Since programs like vi respond to one keypress at a time, rather than read a line at a time like most Unix shell commands, I don't think you can script a vi interaction the way you are trying to.
Oh do pay attention 007. In the wrong hands, this cylindrical 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Use backslash in Applescript running a Bash Shell Script||rebello95||Mac Programming||12||Nov 3, 2011 02:56 PM|
|Applescript shell script won't run when display is sleeping||BlueRevolution||Mac Programming||6||Feb 19, 2011 04:11 AM|
|Help with shell script to invoke screen capture||jammin0||OS X||4||Sep 29, 2010 03:07 PM|
|Trying to create a shell script to cut/paste files in finder. Help needed.||iBug2||OS X||0||Jul 29, 2009 08:11 AM|
|Quicksilver : appending text to a text document from clipboard?||Yaja123||Mac Applications and Mac App Store||2||May 25, 2007 09:58 AM|
All times are GMT -5. The time now is 07:21 PM.