[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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





Le 23.02.2014 02:58, Scott Ferguson a écrit :
On 23/02/14 07:39, berenger.morel@neutralite.org wrote:


Le 20.02.2014 02:15, Scott Ferguson a écrit :
On 19/02/14 23:32, berenger.morel@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.


Reply to: