The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
So, I'm trying to make a BASH script for an automated installation of a few tarballs in OSX. However, there is the slight problem of me not knowing how to make a script! HAH! Whatever, small hurdle...
Anywho, I've been to the OSX scripting site and it seemed relatively straight forward. So I created a little test script. Somehow, I get more lines of errors than I have lines of code. What the fuck?
Here is my code:
#! /bin/bash
$echo "Hello"
It's titled "script.sh" and I used chmod +x to make it executable. However, when I go into bash and type in ~/desktop/script.sh I get the following error:
./script.sh: line 1: {rtf1macansicpg10000cocoartf824cocoasubrtf420: command not found
./script.sh: line 2: syntax error near unexpected token `}'
./script.sh: line 2: `{\fonttbl\f0\fswiss\fcharset77 Helvetica;}'
You edited the script in your word processor and saved it as an .rtf file. Scripts need to be plain text. The operating system doesn't need bold and italics and Comic Sans fonts.
You need to use, like, a text editor. Like TextEdit or vi.
Also it's been a while for me but I don't think you need the $ in front of 'echo'
The '$' shouldn't be there before echo. Usually when you see a '$' at the beginning of a line it is because whatever example you are looking at is being entered directly into the terminal, so $ is the prompt.
Barrakketh on
Rollers are red, chargers are blue....omae wa mou shindeiru
Oops I mistakenly assumed that TextEdit was just the OS X version of the old SimpleText application. Apparently not so. I edit real text files on a mac using vi anyway.
This explains the eight step procedure you have to use to get your Mac plain text editor to actually edit plain text. And people say that it's easier to use, eh? Sigh.
I just have one more question. Is there any way to delete all the files in a folder except ones ending in a specific suffix? A la; when I'm done I want to delete all the files in a directory except those ending in .tar.z
I just have one more question. Is there any way to delete all the files in a folder except ones ending in a specific suffix? A la; when I'm done I want to delete all the files in a directory except those ending in .tar.z
Hrmm, that didn't work out so well. It ended up deleting everything. hrmm....
It's best to do a dry run by not specifying an action to be taken. That said, the example he gave should have worked. I did a similar command using both -name and -iregex and it worked as expected.
find ./ -not -name '*.rar' -exec echo "{}" \;
Which would print the name of the files that don't match the expression. Scanning the output with grep confirmed that it properly excluded all RAR archives.
Barrakketh on
Rollers are red, chargers are blue....omae wa mou shindeiru
Posts
You need to use, like, a text editor. Like TextEdit or vi.
Also it's been a while for me but I don't think you need the $ in front of 'echo'
The '$' shouldn't be there before echo. Usually when you see a '$' at the beginning of a line it is because whatever example you are looking at is being entered directly into the terminal, so $ is the prompt.
Hrmm... I used TextEdit to create the script. Do I need to save it as HTML? The options I'm given are:
RTF
HTML
Word Format
Word XML Format
Well, no, because HTML will save it with HTML markup, won't it?
If you don't have a text editor like TextWrangler or TextMate or SubEthaEdit, you can just do it at the command-line with pico or emacs or vi.
http://docs.info.apple.com/article.html?artnum=106212
This explains the eight step procedure you have to use to get your Mac plain text editor to actually edit plain text. And people say that it's easier to use, eh? Sigh.
Fucking right on!
Thanks for your help everyone.
Now I just need to figure out how to untar these things into directories instead of right where they're located, but that's a job for tomorrow.
v (for 'verbose') is optional, of course, and make sure you add the 'z' flag if your tarballs are compressed with gzip, too.
I just have one more question. Is there any way to delete all the files in a folder except ones ending in a specific suffix? A la; when I'm done I want to delete all the files in a directory except those ending in .tar.z
Any ideas?
Use find.
It's best to do a dry run by not specifying an action to be taken. That said, the example he gave should have worked. I did a similar command using both -name and -iregex and it worked as expected.
Which would print the name of the files that don't match the expression. Scanning the output with grep confirmed that it properly excluded all RAR archives.
I guess it's case sensitive. odd that some commands are and some aren't.
Thank you so much, you have all been really helpful.
If you want it case insensitive, use -iname instead of -name.