Terminal Command

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Terminal Command Thu May 30, 2013 2:42 am • by novajunior
I have these terminal commands that I normally run on a folder

Code: Select all
unzip \*.zip -d .
rm *.zip


I tried to put those into a shell script, however it fails to run. Any ideas on how I can run these commands in a folder?

It basically unzips the multiple zip packages into the current directory and removes the zips.
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Terminal Command Thu May 30, 2013 10:25 am • by a_freyer
The short answer is to use the unarchive feature of Hazel, which does the exact same thing.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Terminal Command Thu May 30, 2013 11:30 am • by sjk
novajunior wrote:
Code: Select all
unzip \*.zip -d .

Why are you quoting the '*' expansion character or is that just a typo here?
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Terminal Command Fri May 31, 2013 1:02 am • by novajunior
I'm not quoting the *. I don't see like that?
Also the unarchive feature does not allow the files to be unzipped into the main directory. Meaning if the zip contains folders, it will not unzip the contents directly into the main folder.
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Terminal Command Fri May 31, 2013 12:52 pm • by Mr_Noodle
The script is not taking the argument into account ($1). Also, I recommend against using relative paths (the -d . part). You should use dirname to get the directory from $1 instead.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Terminal Command Fri May 31, 2013 4:26 pm • by sjk
novajunior wrote:I'm not quoting the *. I don't see like that?

There's a backslash (\) quoting the *.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Terminal Command Fri May 31, 2013 5:07 pm • by a_freyer
@sjk you mean escaping (thus OP's confusion), but that is not what the slash in OP's statement represents.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Terminal Command Fri May 31, 2013 6:35 pm • by novajunior
Thanks for the help guys, I will try out something
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Terminal Command Fri May 31, 2013 10:42 pm • by sjk
a_freyer wrote:@sjk you mean escaping (thus OP's confusion)

From the bash man page:

There are three quoting mechanisms: the escape character, single quotes, and double quotes.

So I meant using the backslash escape character as the quoting mechanism for the asterisk. :)

but that is not what the slash in OP's statement represents.

Then I'm confused about its purpose since the next command uses an unescaped/unquoted asterisk:

Code: Select all
rm *.zip
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Terminal Command Sun Jun 02, 2013 1:34 pm • by a_freyer
It's a directory tree character, not an escaping character in this context. It tells unzip to operate in the current directory. This is because unzip interprets *.zip as a wildcard even after escaping. The answer here is a bit complex because of the odd way unzip processes argv.

That said, 'quoting' is more confusing terminology than 'current directory', even though it may be technically correct (the best kind of correct).

Note the unzip man.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Terminal Command Sun Jun 02, 2013 3:58 pm • by sjk
Got it, thanks! I'd forgotten about the internal wildcard handling of unzip, etc. commands that shell expansions can interfere with.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Terminal Command Fri Sep 06, 2013 1:57 pm • by novajunior
Is there still a way I can do this? I'm not sure what to do anymore
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Terminal Command Fri Sep 06, 2013 6:42 pm • by a_freyer
What do you mean that it fails to run? Does the shell script shoot an error?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Terminal Command Sat Sep 07, 2013 12:54 pm • by novajunior
I'm not sure how to go about writing the shell script. It fails to unzip my files.
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Terminal Command Sat Sep 07, 2013 12:59 pm • by a_freyer
That's not particularly descriptive of the issue that you're facing. Have you tried Mr_Noodle's suggestion of removing the relative path flag?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Next

Return to Support