Append value of a variable to end of a file

I’m a noob trying to write a script that does three things:

  1. Take a series of pre-numbered MP3 files and convert them to WAV files using sox.
  2. Cat the wav files together into several larger wav files based on user input on total number of parts and number of files for each part
  3. Convert the larger wav files to M4A files using faac.

I’ve got the first part down. The second part is proving more tricky. If I have, say, 50 wav files that I want to turn into 5 wav files, I have a dialog that asks how many files there should be total, then dialogs asking for the number of files in each part. If the first part is going to have 10 files, I need my script to pass arguments to sox (i.e. sox 01.wav 02.wav … 10.wav part1.wav). I’m currently trying to use a for loop to append the numbers to a file, then use that file to pass the variables to sox. I can’t seem to figure out how to concatenate the numbers to the file without each number being on a new line. I know there is a TCL command called “append” which seems like it would do what I need, but it can’t be called from a bash script.

I hope I’m being clear enough to elicit some ideas from people who are much more knowledgeable about scripting than I. Thanks for your thoughts.

–chriscrutch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I think this is what you’re after, give or take:

unset MYVAR;for i in seq 0 9; do MYVAR="$MYVAR $i.wav"; done; echo $MYVAR

Good luck.

chriscrutch wrote:
> I’m a noob trying to write a script that does three things:
>
> 1. Take a series of pre-numbered MP3 files and convert them to WAV
> files using sox.
> 2. Cat the wav files together into several larger wav files based on
> user input on total number of parts and number of files for each part
> 3. Convert the larger wav files to M4A files using faac.
>
> I’ve got the first part down. The second part is proving more tricky.
> If I have, say, 50 wav files that I want to turn into 5 wav files, I
> have a dialog that asks how many files there should be total, then
> dialogs asking for the number of files in each part. If the first part
> is going to have 10 files, I need my script to pass arguments to sox
> (i.e. sox 01.wav 02.wav … 10.wav part1.wav). I’m currently trying to
> use a for loop to append the numbers to a file, then use that file to
> pass the variables to sox. I can’t seem to figure out how to
> concatenate the numbers to the file without each number being on a new
> line. I know there is a TCL command called “append” which seems like it
> would do what I need, but it can’t be called from a bash script.
>
> I hope I’m being clear enough to elicit some ideas from people who are
> much more knowledgeable about scripting than I. Thanks for your
> thoughts.
>
> --chriscrutch
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJKxWKdAAoJEF+XTK08PnB5L4MP/0glpMioYANzTkL40/gY2D7o
adTm5FwY37WyXmt5wxWUapCvxEnlPjaF2brk16avPMTOZzxIjIo4YTmcFj1FO8C6
6FL1ItRnCsOytt0U3/unuxqrsKphAQdpo3nuXX/JtVgVFJmShjRVVUW3joZgavmR
7WjBzeYwGhiygANsK6kqJ8FPlecp5Kq5ZFj+Hh1MiJI4bDlxP8r0MXjzHn7+sKFi
v1E9bpNyMSEPNiyZXqM8oiGfUwBFIiaRut/uGtozY3GHPwWysKHmIrs3MN2DFWxJ
TF8IPU8LYyqlA+fpEBmdmOVyIWkOznfiTCjrlghRLzJzJt9/3dMB+HH64Q0n76hh
Xh8TJ0rlumcj2pfGJjEzs5jW6hiOqcqKpxsUzpO6xUiy6Ng5FpLZ0yXD42TOKkla
VrgJ2ffwhwuyOuxvAdNL+0hwXuXiYKGV/Ml4D3admM2DTG7beAJiL+gxv42SIV59
HUOeiC8Kjc5oM9BYB9duiptJVO2RU4zAWkpxXHVYtPK969WOolNPtieXz/JEw964
pDFzWV1CdLjMMueA+gi8NJGBITXgQ8z6m7Vftbscyv6NhZqmdI88JEg7ccGPoZj4
dQCO/CxUzmCLnBwMlHun0w4BsK7TYqKIET7uwEZNojL9vdN9B6+JoNRZM9866pGh
Bt1Bt8GTjQpKAq/Jwjm+
=dtQA
-----END PGP SIGNATURE-----

Beautiful. Script works well after using your code and finishing the rest of it. Thank you.

–chriscrutch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

No problem. Thanks for confirming.

Good luck.

chriscrutch wrote:
> Beautiful. Script works well after using your code and finishing the
> rest of it. Thank you.
>
> --chriscrutch
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJKxXN9AAoJEF+XTK08PnB5q9sP/0mB3WkyGXFYd0u9b+u9Jumo
JPlDMgi4AMmj/TqUilvJxxVt2l5XuOrqJ0NmHNJVu8HNsZFFBPOJgJ3nsBAIFfQa
PnRQh58B3fBYiUuw+kwqgVuDQMswOYQF4kqcYgquwsb2ciraceOcWnmg4JWApILv
rVmKYClzG5S5IV/Zk76azwYoR6++AsMAtNG2pDO/X0l7gMcnXdUM0V7FBFApsZty
99iebjYVKs8zRWQqbuyrCBRNpW26bqjKy9+p8SkiO7d036KnLS1pbqGnOnhwKHmx
4u4uUhhQ4iPUR+PThbXXJVrijkc1QqGQ8WJaHlBQr0P4RnuZeTmVxKtPlXhzxVFa
9KWPUUaUljE2BLfA4noIA7mSTqvwa11+iIALtXKnEbCQtiug+PLw1XWfedVMB/uv
ZYQ4LXU4J4gHRBExOWlum4fHNqISEo5AO4HIWkkqhUU2rq4gfG5TbU3t9XQtaG5x
TB4dg1cvSLswUEkiNEx34lkCuES0T2rmR5E5oXTAydcWof/7x5wwHOdVN9wLxJfz
e38QwxxjVXN+YdL+ytO5/6UnsIMXukXDCLEGbRt2ehxrziHnIAm1rzP/1HZsHony
DKkXwqLWiRE4ovkTLk/vn1CayuXhiyntvWQt3jjhvF3Kpy8UV5svNl36+cC8D7Qu
l1VXaq1u7b4nyCpZ2AW1
=4RE+
-----END PGP SIGNATURE-----

with bash, you can just do


for i in {0..9}

no need external command