Quote:
Originally Posted by stf92
Given the directory structure in post #1 the program should play (mplayer) files including the string 'concerto no. 27' which are one directory level below that in which the program will be run. I came up with
Code:
### PROG APPL: this script run in directory /almacen/Nonsoft/musica/mozart/Mozart - Complete Piano Concertos
### will play concert #27 (all movements).
for f in CD\ ??/*; do
nr=${f:49:2} #Pick up the concert number
na=${f:30:5} #There also are rondos. I only want piano concertos
# echo $nr
# echo $na
if [ "$na" = "Piano" ]; then
if [ "$nr" = "27" ]; then
echo $f
mplayer "$f"
fi
fi
done
which is working fine. All I need now is to replace "27" by $1 and I'll obviate the work of searching all directories (the CD/ ??) to find the concert I want to here (the uploader placed each track (movement) in a separate file!) thanks to your post.
|
it had nothing to do with my post, if you're referring to me, without mentioning names. then expect everyone to know who you're talking to, so giving deduction a try, it has to be me because I am the only other one that posed in here. all I did was told you the correct way to assigning a value to your variable. just like you asked about.
Quote:
However I get 'Command not found' in line 2. How do I assign the substring to nr?
|
what your code does is your doing not mine. I take NO credit in it for what it actually does whatsoever. I did not write that code, so I hold no responsibility for what it does.
I do not even know what it does other than chop off your strings, and if they are malformed, then yes, you are going to run into complications.
you are going to have to come up with ways to compensate for the deviation in strings, or come up with a different method to make allowances for the deviations to be there and correct itself to deal with them, either way, I'd come up with a method to try and make them all the same 'pattern' in my strings so all I'd have to do is find that pattern to get what I want and nothing else, so I would not have to go through all of that if it this do this and if it is something else then to this code to match strings to get what I want.
you already have shown you know what you are looking for in the string, now all that needs to be done is make sure that every string adheres to that standard you provided the code to use to get what you are looking for.
as I see you already know you have to put a few more lines of code in there to make sure that you get what you want. you can try sub string matching like this too,
Code:
substring=whatIwant
for or while loop taking in strings
if [[ "string" =~ "$substring" ]] ;
then
do something about it.
else
skip it
fi
--------
substring1=oneThing
substring2=AnotherThing
[[ "$string" =~ "$substring1" ]] && do something on this match
[[ "$string" =~ "$substring2" ]] && do something on this match
etc..
-----------
if [ "$na" = "Piano" ]; then
if [ "$nr" = "27" ]; then
echo $f
mplayer "$f"
fi
fi
-------- CAN be this ----------
if [ "$na" = "Piano" ] && [ "$nr" = "27" ]; then
{
do something
}
fi
could be this too,
if [ "$f" =~ "Piano" ] && [ "$f" =~ "27" ]; then
{
do something
}
fi
but you have to understand how that works too.
Nor do I see how your code in post one could do anything other than assign a value to variable then echo the results, so .. what are you taking about thanks to me your code moved everything into
Quote:
" (the uploader placed each track (movement) in a separate file"thanks to your post.
|
looks like you already know who's at fault here, the uploader placed each track in a separate file,
thanks to me? I did not even write the code of that program, so stop throwing blame at me or anywhere else but yourself for your mistakes for not knowing what your "uploader" was going to do.