Re: 7z command works fine on command line but not in script

2014-02-23 Thread berenger . morel



Le 23.02.2014 02:58, Scott Ferguson a écrit :

On 23/02/14 07:39, berenger.mo...@neutralite.org wrote:



Le 20.02.2014 02:15, Scott Ferguson a écrit :

On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:



Le 19.02.2014 10:53, Scott Ferguson a écrit :

Just read your last post before sending this, so this may no
longer be relevant... I don't know that you need to quote the
variables. I use coloured bash


coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I
meant to write. If anyone knows of a way to colourise the syntax in
xterm (especially 'fc' temp) I'd be *very* interested.


I think I did not read correctly when I replied to you.


No. The mistake was mine (I didn't write editor originally).

I also use syntactic coloration in my editors, I'm a programmer 
after

all. And vim manages it correctly enough... Still, it did not helped
me with *that* pebcak. The only things colored in my shell is not
bash, btw, only the prompt... indeed, a colored shell would be very,
very powerful.



Darac (Paul?) made a suggestion about that - there is also fish.


Yes, and I intend to try those alternatives. Might be interesting, 
since I only use bash because it's default choice.




snipped






but for a reason I can not understand, echo did not displayed
them.


I'm not sure if you mean echo as in your example:-
for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir $artiste/$album -p
7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
echo 7z x \$i\ -o\$artiste/$album\
done


If so, perhaps it's the way you were using echo? It displays the 
string
- including the spaces, but when you use the string with 7z it's 
working

with only working with the first word/character before the space -
because you're escaping the last  in each string.

So if artiste is Frank Zappa and album is Weasels Rip My Flesh 
then

those variables will display fine with echo, but because you were
escaping the parenthesis  7z is trying to work with Frank, not Frank
Zappa. And if the artiste or album contains a minus character


Maybe. I do not really know why my first version was wrong, shell 
scripting's syntax is really horrible, in my opinion. Probably because I 
do not play with it enough, I have troubles to understand what to escape 
or not. C and C++ are far simpler for me, only 1 string delimiter ( , 
since ' is for character ) and one character to escape it ( and few 
other things, but it's not hard to find clean documentation about them 
IMO. )



If you'd done the same thing with rmdir the mistake would have been
obvious.




(I altered that section too - just in case you have more than
one album by an artist.)


I only remove one precise album, because there is only one per archive. 
And it was only here while I was debugging, since I did not wanted to do 
the removing manually each time I changed an escape or whatever. I'm 
lazy, that's why I made that script, right? :)




Note also - if you want to echo escape characters you need to use the 
-e

switch, or just avoid them altogether - I'd, cautiously (I haven't
tested it, and I'd prefer more error checking) suggest this 
variation:-



for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir -p $artiste/$album
7z x $i -o $artiste/$album || rmdir $artiste/$album
echo 7z x $i -o $artiste/$album
done


snipped

Kind regards


I do not have the script here, but I think I ended with something like 
this. Except for the space between -o and $artiste/$album, since 7z does 
not accept that ( leads to incorrect command line ). I think I have 
sent the working script in reply to my first email.



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/a82addced07ae33bf5b107290544d...@neutralite.org



Re: 7z command works fine on command line but not in script

2014-02-22 Thread berenger . morel



Le 20.02.2014 02:15, Scott Ferguson a écrit :

On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:



Le 19.02.2014 10:53, Scott Ferguson a écrit :
Just read your last post before sending this, so this may no longer 
be
relevant... I don't know that you need to quote the variables. I 
use

coloured bash


coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I 
meant

to write. If anyone knows of a way to colourise the syntax in xterm
(especially 'fc' temp) I'd be *very* interested.


I think I did not read correctly when I replied to you. I also use 
syntactic coloration in my editors, I'm a programmer after all. And vim 
manages it correctly enough... Still, it did not helped me with *that* 
pebcak.
The only things colored in my shell is not bash, btw, only the 
prompt... indeed, a colored shell would be very, very powerful.




[*1.] https://github.com/tihirvon/dex


so it is usually obvious if I need to. P.S. without the
quotes you won't need the escapes - just quote the whole filename 
(which

may be what you are lacking).


I use colors too ( and I have no idea about the reason to disable 
colors

by default in Debian... ), but I really do not like interpreted
languages. My opinion is that stuff written with them are messy, but 
at
least, shell is handier than C++ to manage files and shell 
commands...
so sometimes I try to automate small tasks with it. Maybe someday I 
will

become efficient with it.


I keep telling myself the same thing - in the meantime I debug (with 
a

hammer).



The error was that I had too many quotes, so some of them were 
included

in the name,


I noted Andre's response (and keener eye)
The #!/bin/(bash or sh) -x is useful, after parsing the script you'll
see the outcomes on screen

You may find these useful:-
set -x# same as the minus x in the shell invocation 
line
trap echo hit return;read x DEBUG  # step through one line at a 
time

set -o nounset# display unset variables
function pause(){ # wot it says
   read -p $*
}
#pause 'Press [Enter] key to continue...'




It will probably help me a lot.




but for a reason I can not understand, echo did not
displayed them.


Colourised nano/vim etc might make it easier to spot.
I've linked my (dodgy) ~/.bashrc in case it proves useful (you should
avoid the lines followed by hack comments.)

If you wish:-
$ mv ~/.bashrc{,.bak}
replace with my version
http://paste.debian.net/82999
$ . .~/bashrc


I use the nano syntax rules from:-
https://github.com/nanorc/nanorc


Having a repo with my config files and script is something I really 
should do also...




snipped

Kind regards



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/83d3116c5f86fb1a241fbfdfb8b4d...@neutralite.org



Re: 7z command works fine on command line but not in script

2014-02-22 Thread Scott Ferguson
On 23/02/14 07:39, berenger.mo...@neutralite.org wrote:
 
 
 Le 20.02.2014 02:15, Scott Ferguson a écrit :
 On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:
 
 
 Le 19.02.2014 10:53, Scott Ferguson a écrit :
 Just read your last post before sending this, so this may no
 longer be relevant... I don't know that you need to quote the
 variables. I use coloured bash
 
 coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I
 meant to write. If anyone knows of a way to colourise the syntax in
 xterm (especially 'fc' temp) I'd be *very* interested.
 
 I think I did not read correctly when I replied to you.

No. The mistake was mine (I didn't write editor originally).

 I also use syntactic coloration in my editors, I'm a programmer after
 all. And vim manages it correctly enough... Still, it did not helped
 me with *that* pebcak. The only things colored in my shell is not
 bash, btw, only the prompt... indeed, a colored shell would be very,
 very powerful.


Darac (Paul?) made a suggestion about that - there is also fish.

snipped

 
 
 but for a reason I can not understand, echo did not displayed
 them.

I'm not sure if you mean echo as in your example:-
for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir $artiste/$album -p
7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
echo 7z x \$i\ -o\$artiste/$album\
done


If so, perhaps it's the way you were using echo? It displays the string
- including the spaces, but when you use the string with 7z it's working
with only working with the first word/character before the space -
because you're escaping the last  in each string.

So if artiste is Frank Zappa and album is Weasels Rip My Flesh then
those variables will display fine with echo, but because you were
escaping the parenthesis  7z is trying to work with Frank, not Frank
Zappa. And if the artiste or album contains a minus character If
you'd done the same thing with rmdir the mistake would have been
obvious. (I altered that section too - just in case you have more than
one album by an artist.)

Note also - if you want to echo escape characters you need to use the -e
switch, or just avoid them altogether - I'd, cautiously (I haven't
tested it, and I'd prefer more error checking) suggest this variation:-


for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir -p $artiste/$album
7z x $i -o $artiste/$album || rmdir $artiste/$album
echo 7z x $i -o $artiste/$album
done


snipped

Kind regards


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/530955d1@gmail.com



Coloured CLI [was: Re: 7z command works fine on command line but not in script]

2014-02-20 Thread Darac Marjal
On Thu, Feb 20, 2014 at 12:15:56PM +1100, Scott Ferguson wrote:
 On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:
  
  
  Le 19.02.2014 10:53, Scott Ferguson a écrit :
  Just read your last post before sending this, so this may no longer be
  relevant... I don't know that you need to quote the variables. I use
  coloured bash
 
 coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I meant
 to write. If anyone knows of a way to colourise the syntax in xterm
 (especially 'fc' temp) I'd be *very* interested.

Does it have to be bash?

If you're willing to give zsh a try (It's another bourne-derivative, so
the syntax is very similar. I believe it's mostly POSIX compliant, too),
then add-ons such as oh-my-zsh[1] or zprezto[2] have syntax-highlighting
modules. (I found oh-my-zsh to be a good window to the power of zsh, but
zprezto seems to be generally better).

[1] https://github.com/robbyrussell/oh-my-zsh
[2] https://github.com/sorin-ionescu/prezto



signature.asc
Description: Digital signature


Re: Coloured CLI [was: Re: 7z command works fine on command line but not in script]

2014-02-20 Thread Scott Ferguson
On 20/02/14 20:24, Darac Marjal wrote:
 On Thu, Feb 20, 2014 at 12:15:56PM +1100, Scott Ferguson wrote:
 On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:


 Le 19.02.2014 10:53, Scott Ferguson a écrit :
 Just read your last post before sending this, so this may no longer be
 relevant... I don't know that you need to quote the variables. I use
 coloured bash

 coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I meant
 to write. If anyone knows of a way to colourise the syntax in xterm
 (especially 'fc' temp) I'd be *very* interested.
 
 Does it have to be bash?

No! It's just what I use (for reasons too lengthy and boring for the list).
I'd settle for a simple way to pipe `fg` (/temp) into nano so I can use
colours to spot syntax errors.

 
 If you're willing to give zsh a try (It's another bourne-derivative, so
 the syntax is very similar. I believe it's mostly POSIX compliant, too),
 then add-ons such as oh-my-zsh[1] or zprezto[2] have syntax-highlighting
 modules. (I found oh-my-zsh to be a good window to the power of zsh, but
 zprezto seems to be generally better).

I've only tried zsh. It was nice.


Have you tried fish? It has coloured CLI syntax highlighting.
# apt-get install fish
http://fishshell.com/

 
 [1] https://github.com/robbyrussell/oh-my-zsh
 [2] https://github.com/sorin-ionescu/prezto
 


Kind regards


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5305fa58.3040...@gmail.com



Re: 7z command works fine on command line but not in script

2014-02-19 Thread Scott Ferguson
On 19/02/14 19:47, berenger.mo...@neutralite.org wrote:
 Hello.
 
 I made a script to extract music from a jamendo archive, but for a
 reason I do not know, 7z does not accept the command line. I also echoed
 it, to be able to know what it tries to run, and it works fine when ran
 on command line.
 
 Here is the script:
 
 #!/bin/sh
 
 for i in *.zip;
 do
 artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
 album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
 mkdir $artiste/$album -p
 7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
 echo 7z x \$i\ -o\$artiste/$album\
 done
 
 With, for example, this archive:
 http://www.jamendo.com/fr/list/a69778/monument, the folders are
 correctly created, but it prints:
 Error: Incorrect command line
 7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
 -oShearer/Monument
 
 Do someone knows what I am doing wrong?
 
 

Maybe passing - without a recognised qualifier (after the
$artiste/$album\) ??

Kind regards


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5304711...@gmail.com



Re: 7z command works fine on command line but not in script

2014-02-19 Thread berenger . morel



Le 19.02.2014 09:53, Scott Ferguson a écrit :

On 19/02/14 19:47, berenger.mo...@neutralite.org wrote:

Hello.

I made a script to extract music from a jamendo archive, but for a
reason I do not know, 7z does not accept the command line. I also 
echoed
it, to be able to know what it tries to run, and it works fine when 
ran

on command line.

Here is the script:

#!/bin/sh

for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir $artiste/$album -p
7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
echo 7z x \$i\ -o\$artiste/$album\
done

With, for example, this archive:
http://www.jamendo.com/fr/list/a69778/monument, the folders are
correctly created, but it prints:
Error: Incorrect command line
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
-oShearer/Monument

Do someone knows what I am doing wrong?




Maybe passing - without a recognised qualifier (after the
$artiste/$album\) ??

Kind regards


It does not change anything.

I have some progress, when I do this:
7z x \'$i\' -o\'$artiste/$album\'
instead of
7z x \$i\ -o\$artiste/$album\

But the the error become there is no such archive. I wonder if the 
easier would not be to try another unarchiver...



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/b2048fe8fce96637174cdf370f858...@neutralite.org



Re: 7z command works fine on command line but not in script

2014-02-19 Thread berenger . morel



Le 19.02.2014 10:30, berenger.mo...@neutralite.org a écrit :

Le 19.02.2014 09:53, Scott Ferguson a écrit :

On 19/02/14 19:47, berenger.mo...@neutralite.org wrote:

Hello.

I made a script to extract music from a jamendo archive, but for a
reason I do not know, 7z does not accept the command line. I also 
echoed
it, to be able to know what it tries to run, and it works fine when 
ran

on command line.

Here is the script:

#!/bin/sh

for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir $artiste/$album -p
7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
echo 7z x \$i\ -o\$artiste/$album\
done

With, for example, this archive:
http://www.jamendo.com/fr/list/a69778/monument, the folders are
correctly created, but it prints:
Error: Incorrect command line
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
-oShearer/Monument

Do someone knows what I am doing wrong?




Maybe passing - without a recognised qualifier (after the
$artiste/$album\) ??

Kind regards


It does not change anything.

I have some progress, when I do this:
7z x \'$i\' -o\'$artiste/$album\'
instead of
7z x \$i\ -o\$artiste/$album\

But the the error become there is no such archive. I wonder if the
easier would not be to try another unarchiver...


Ok, I have found the error, thanks to unzip and it's real error 
messages ( it does not just says I failed, but it explains the reason, 
by giving what names it tried, which is the only good way to allow a 
user to understand what is the problem, imo. I may start to use it for 
real I guess. ).

The correct line is:
7z x $i -o$artiste/$album

I just wonder how it will behave if there are more exotic names... but 
I'll see that when I'll have the problem, for now it works. Thanks for 
help.



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/a6ea1a7cd91aaa93846afccdb0941...@neutralite.org



Re: 7z command works fine on command line but not in script

2014-02-19 Thread Scott Ferguson
Just read your last post before sending this, so this may no longer be
relevant... I don't know that you need to quote the variables. I use
coloured bash so it is usually obvious if I need to. P.S. without the
quotes you won't need the escapes - just quote the whole filename (which
may be what you are lacking).

On 19/02/14 20:30, berenger.mo...@neutralite.org wrote:
 
 
 Le 19.02.2014 09:53, Scott Ferguson a écrit :
 On 19/02/14 19:47, berenger.mo...@neutralite.org wrote:
 Hello.

 I made a script to extract music from a jamendo archive, but for a
 reason I do not know, 7z does not accept the command line. I also echoed
 it, to be able to know what it tries to run, and it works fine when ran
 on command line.

 Here is the script:

 #!/bin/sh

 for i in *.zip;
 do
 artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
 album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
 mkdir $artiste/$album -p
 7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p
 echo 7z x \$i\ -o\$artiste/$album\
 done

 With, for example, this archive:
 http://www.jamendo.com/fr/list/a69778/monument, the folders are
 correctly created, but it prints:
 Error: Incorrect command line
 7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
 -oShearer/Monument

 Do someone knows what I am doing wrong?



 Maybe passing - without a recognised qualifier (after the
 $artiste/$album\) ??

 Kind regards
 
 It does not change anything.
 
 I have some progress, when I do this:
 7z x \'$i\' -o\'$artiste/$album\'
 instead of
 7z x \$i\ -o\$artiste/$album\

7z x $i -o $artiste/$album ?

I'm presuming you mean in the script (so the variants are populated).
What happens if you try this from the CLI:-
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip

I'm also presuming you're running the command in the working directory
(stuff I often overlook).

 
 But the the error become there is no such archive.

Is it there?  i.e.:-
$ ls Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip

I'd also try renaming it:-
$ cp Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
Shearer-Monument-a69778-Jamendo-MP3 VBR 192k.zip
and then trying again

 I wonder if the
 easier would not be to try another unarchiver...
 
 

unzip?  Though 7z is pretty good.

Kind regards.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/53047f0f.5050...@gmail.com



Re: 7z command works fine on command line but not in script

2014-02-19 Thread Andre Majorel
On 2014-02-19 09:47 +0100, berenger.mo...@neutralite.org wrote:
 Hello.
 
 I made a script to extract music from a jamendo archive, but for a
 reason I do not know, 7z does not accept the command line. I also
 echoed it, to be able to know what it tries to run, and it works
 fine when ran on command line.
 
 Here is the script:
 
 #!/bin/sh
 
 for i in *.zip;
 do

You only need the semicolon if the do is on the same line as
the for, as in

  for i in *.zip; do

   artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
   album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`

/g after an anchored regexp is meaningless (the regexps are
anchored so cannot match more than once).

   mkdir $artiste/$album -p

Putting -p after the argument is not portable (only works with
GNU getopt). -- before the argument is probably not needed
here because - is your separator but it's a good habit to
take.

  mkdir -p -- $artiste/$album

   7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p

If the double inverted commas are escaped with backslashes, they
will be passed to the command. Is this really what you want ?
Don't you mean this instead ?

  7z x -o $artiste/$album $i

   echo 7z x \$i\ -o\$artiste/$album\

To see what was executed, you can use set -x.

 done

 With, for example, this archive:
 http://www.jamendo.com/fr/list/a69778/monument, the folders are
 correctly created, but it prints:
 Error: Incorrect command line
 7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
 -oShearer/Monument
 
 Do someone knows what I am doing wrong?

-- 
André Majorel http://www.teaser.fr/~amajorel/
Plusieurs grandes marques de spambots recommandent lists.debian.org.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20140219112048.gb6...@aym.net2.nerim.net



Re: 7z command works fine on command line but not in script

2014-02-19 Thread berenger . morel



Le 19.02.2014 10:53, Scott Ferguson a écrit :
Just read your last post before sending this, so this may no longer 
be

relevant... I don't know that you need to quote the variables. I use
coloured bash so it is usually obvious if I need to. P.S. without the
quotes you won't need the escapes - just quote the whole filename 
(which

may be what you are lacking).


I use colors too ( and I have no idea about the reason to disable 
colors by default in Debian... ) , but I really do not like interpreted 
languages. My opinion is that stuff written with them are messy, but at 
least, shell is handier than C++ to manage files and shell commands... 
so sometimes I try to automate small tasks with it. Maybe someday I will 
become efficient with it.


The error was that I had too many quotes, so some of them were included 
in the name, but for a reason I can not understand, echo did not 
displayed them. I spotted the problem thanks to unzip, which is far 
nicer than 7z when it comes to reporting errors to user, because it 
shows the exact filename it was trying to process when failed.
I like 7z, it have pretty nice options and can manage almost all format 
and compression methods ( I only have found 2 that it can not process, 
and one can be if the non-free package is installed, which is better 
than any other archiver I know about ) and, which is very important, it 
can detect the format alone. Pretty useful for scripts, but when it 
fails, it only says it fails, not why it did.




On 19/02/14 20:30, berenger.mo...@neutralite.org wrote:



Le 19.02.2014 09:53, Scott Ferguson a écrit :

On 19/02/14 19:47, berenger.mo...@neutralite.org wrote:

Hello.

I made a script to extract music from a jamendo archive, but for a
reason I do not know, 7z does not accept the command line. I also 
echoed
it, to be able to know what it tries to run, and it works fine 
when ran

on command line.

Here is the script:

#!/bin/sh

for i in *.zip;
do
artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
mkdir $artiste/$album -p
7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album 
-p

echo 7z x \$i\ -o\$artiste/$album\
done

With, for example, this archive:
http://www.jamendo.com/fr/list/a69778/monument, the folders are
correctly created, but it prints:
Error: Incorrect command line
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
-oShearer/Monument

Do someone knows what I am doing wrong?




Maybe passing - without a recognised qualifier (after the
$artiste/$album\) ??

Kind regards


It does not change anything.

I have some progress, when I do this:
7z x \'$i\' -o\'$artiste/$album\'
instead of
7z x \$i\ -o\$artiste/$album\


7z x $i -o $artiste/$album ?


The destination directory needs to be just near the option -o, 
otherwise it does not work.




I'm presuming you mean in the script (so the variants are 
populated).

What happens if you try this from the CLI:-
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip


It extracts the archive into current directory ( and since jamendo just 
archive files without directory, it makes things a lot messy :) )




I'm also presuming you're running the command in the working 
directory

(stuff I often overlook).


I did run the script in the directory where the archives I want to 
process are, and when I tried the command by hand, I was in the same 
place, but it worked.






But the the error become there is no such archive.


Is it there?  i.e.:-
$ ls Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip


It is.


I'd also try renaming it:-
$ cp Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
Shearer-Monument-a69778-Jamendo-MP3 VBR 192k.zip
and then trying again


I would have done this if I were not able to avoid this manipulation.




I wonder if the
easier would not be to try another unarchiver...




unzip?  Though 7z is pretty good.

Kind regards.


Yes, I used unzip to debug the script. This tool actually what it tried 
to do if and when it fails, which revealed me that I had too much tries 
to escape things. I am really not a script guy btw, and am far more 
efficient with strong typed languages, where behaviors are much more 
predictable.


Just in case, here is the full working script.
If someone have any comment to make it more secure, reliable, readable 
or whatever, I'll be happy to read it. Here, it seems it works like a 
charm ( just a little too verbose, but I could easily redirect 7z's 
outputs to /dev/null ).
Note that it updates mpd's database and... remove executable flag from 
songs, since for a reason I can not see, jamendo set it up! It also 
moves the archive out of the way, to allow running the script on next 
download without a problem ( downloading a list of archives depending on 
album+author or the id number could be an interesting feature, maybe 
I'll try to do so later, but it would be smarter to do so in another 
script 

Re: 7z command works fine on command line but not in script

2014-02-19 Thread berenger . morel



Le 19.02.2014 12:20, Andre Majorel a écrit :

On 2014-02-19 09:47 +0100, berenger.mo...@neutralite.org wrote:

Hello.

I made a script to extract music from a jamendo archive, but for a
reason I do not know, 7z does not accept the command line. I also
echoed it, to be able to know what it tries to run, and it works
fine when ran on command line.

Here is the script:

#!/bin/sh

for i in *.zip;
do


You only need the semicolon if the do is on the same line as
the for, as in

  for i in *.zip; do


artiste=`echo $i|cut -f1 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`
album=`echo $i|cut -f2 -d-|sed -e 's/^ *//g' -e 's/ *$//g'`


/g after an anchored regexp is meaningless (the regexps are
anchored so cannot match more than once).


mkdir $artiste/$album -p


Putting -p after the argument is not portable (only works with
GNU getopt). -- before the argument is probably not needed
here because - is your separator but it's a good habit to
take.

  mkdir -p -- $artiste/$album


7z x \$i\ -o\$artiste/$album\ || rmdir $artiste/$album -p


If the double inverted commas are escaped with backslashes, they
will be passed to the command. Is this really what you want ?
Don't you mean this instead ?

  7z x -o $artiste/$album $i


echo 7z x \$i\ -o\$artiste/$album\


To see what was executed, you can use set -x.


done



With, for example, this archive:
http://www.jamendo.com/fr/list/a69778/monument, the folders are
correctly created, but it prints:
Error: Incorrect command line
7z x Shearer - Monument - a69778 --- Jamendo - MP3 VBR 192k.zip
-oShearer/Monument

Do someone knows what I am doing wrong?


--
André Majorel http://www.teaser.fr/~amajorel/
Plusieurs grandes marques de spambots recommandent lists.debian.org.



Thanks for the advices.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/b9fb8adc74d517f8e0b5054406d3d...@neutralite.org



Re: 7z command works fine on command line but not in script

2014-02-19 Thread Scott Ferguson
On 19/02/14 23:32, berenger.mo...@neutralite.org wrote:
 
 
 Le 19.02.2014 10:53, Scott Ferguson a écrit :
 Just read your last post before sending this, so this may no longer be
 relevant... I don't know that you need to quote the variables. I use
 coloured bash

coloured *editor* i.e. nano, vi/emac, dex[*1] or Kwrite is what I meant
to write. If anyone knows of a way to colourise the syntax in xterm
(especially 'fc' temp) I'd be *very* interested.

[*1.] https://github.com/tihirvon/dex

 so it is usually obvious if I need to. P.S. without the
 quotes you won't need the escapes - just quote the whole filename (which
 may be what you are lacking).
 
 I use colors too ( and I have no idea about the reason to disable colors
 by default in Debian... ), but I really do not like interpreted
 languages. My opinion is that stuff written with them are messy, but at
 least, shell is handier than C++ to manage files and shell commands...
 so sometimes I try to automate small tasks with it. Maybe someday I will
 become efficient with it.

I keep telling myself the same thing - in the meantime I debug (with a
hammer).

 
 The error was that I had too many quotes, so some of them were included
 in the name,

I noted Andre's response (and keener eye)
The #!/bin/(bash or sh) -x is useful, after parsing the script you'll
see the outcomes on screen

You may find these useful:-
set -x# same as the minus x in the shell invocation line
trap echo hit return;read x DEBUG  # step through one line at a time
set -o nounset# display unset variables
function pause(){ # wot it says
   read -p $*
}
#pause 'Press [Enter] key to continue...'



 but for a reason I can not understand, echo did not
 displayed them. 

Colourised nano/vim etc might make it easier to spot.
I've linked my (dodgy) ~/.bashrc in case it proves useful (you should
avoid the lines followed by hack comments.)

If you wish:-
$ mv ~/.bashrc{,.bak}
replace with my version
http://paste.debian.net/82999
$ . .~/bashrc


I use the nano syntax rules from:-
https://github.com/nanorc/nanorc

snipped

Kind regards


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5305574c.40...@gmail.com