convert DOS bat to Bash script

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

convert DOS bat to Bash script

sauna-l
Hello,

I'm editing/using several batch convert sox scripts under DOS (well,
Windows cmd line ...) which are basically based on this :

cd %~dp0
mkdir converted
FOR %%A IN (%*) DO ---- sox location, parameters and settings ----- %%A
"converted/%%~nA.wav"
pause

and would have to transcript this for Mac (Unix) shell (Bourne Shell,
bash ...)

I can currently make some sox Mac-shell scripts, but can't reproduce the
above feature which allows me to drag and drop folders into the command
line as an input, and create an output folder in the input files folder.


My first attempt is to literally translate every term of the DOS script
into Bash, but of course it fails ...
e.g :

#!/bin/sh

cd $~dp0
mkdir converted

' not sure about the first line but might be ok ...



for A in [$*]; do

' doesn't seem to work


$$A "converted/$$~nA.wav"

' don't think I need the $$ that way but didn't find a way to make it
work


sleep

' not even sure about that one

Any help would be greatly appreciated

Thanks very much in advance




------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Pander


On 19 December 2014 12:55:47 CET, sauna-l <[hidden email]> wrote:

>Hello,
>
>I'm editing/using several batch convert sox scripts under DOS (well,
>Windows cmd line ...) which are basically based on this :
>
>cd %~dp0
>mkdir converted
>FOR %%A IN (%*) DO ---- sox location, parameters and settings ----- %%A
>
>"converted/%%~nA.wav"
>pause
>
>and would have to transcript this for Mac (Unix) shell (Bourne Shell,
>bash ...)
>
>I can currently make some sox Mac-shell scripts, but can't reproduce
>the
>above feature which allows me to drag and drop folders into the command
>
>line as an input, and create an output folder in the input files
>folder.
>
>
>My first attempt is to literally translate every term of the DOS script
>
>into Bash, but of course it fails ...
>e.g :
>
>#!/bin/sh
>
>cd $~dp0
>mkdir converted
>
>' not sure about the first line but might be ok ...
>
>
>
>for A in [$*]; do
>
>' doesn't seem to work
>
>
>$$A "converted/$$~nA.wav"
>
>' don't think I need the $$ that way but didn't find a way to make it
>work
>
>
>sleep
>
>' not even sure about that one
>
>Any help would be greatly appreciated
>
>Thanks very much in advance
>

You could install bash via cygwin.


>
>
>
>------------------------------------------------------------------------------
>Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>from Actuate! Instantly Supercharge Your Business Reports and
>Dashboards
>with Interactivity, Sharing, Native Excel Exports, App Integration &
>more
>Get technology previously reserved for billion-dollar corporations,
>FREE
>http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>_______________________________________________
>Sox-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/sox-users


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Chris Angelico
In reply to this post by sauna-l
On Fri, Dec 19, 2014 at 10:55 PM, sauna-l <[hidden email]> wrote:
> I can currently make some sox Mac-shell scripts, but can't reproduce the
> above feature which allows me to drag and drop folders into the command
> line as an input, and create an output folder in the input files folder.

Suggestion: Start right back at the beginning, which is here at this
human-readable explanation of purpose, and reinvent the script from
there. Either bash or Python would serve you well, I think. (So would
Pike, except that it's a rather obscure language.) Reimplementing an
existing batch file for another shell is usually not worth the hassle.

ChrisA

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Jan Stary
On Dec 19 12:55:47, [hidden email] wrote:

> I'm editing/using several batch convert sox scripts under DOS (well,
> Windows cmd line ...) which are basically based on this :
>
> cd %~dp0
> mkdir converted
> FOR %%A IN (%*) DO ---- sox location, parameters and settings ----- %%A
> "converted/%%~nA.wav"
> pause
>
> and would have to transcript this for Mac (Unix) shell (Bourne Shell,
> bash ...)

Your question is a cmd-vs-shell question,
and is not related to SoX in any way.

> Any help would be greatly appreciated

Run "man sh" on your mac and read it.
That will leave you in a good shape
to write a rudimentary for-loop.

On Dec 19 23:52:49, [hidden email] wrote:
> Either bash or Python would serve you well, I think. [...]
> Reimplementing an existing batch file for another shell
> is usually not worth the hassle.

Note the "sh" above. I think Mac's sh(1) is actually bash(1),
but there is nothing bash-specific you would need for this.
Write a sh(1) script, not a bash(1) script, so you that you can run it
with any other shell on any other UNIX machine.

        Jan


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Fmiser
In reply to this post by sauna-l
> sauna-l wrote:
>
> I'm editing/using several batch convert sox scripts under DOS
 

> cd %~dp0
> mkdir converted
> FOR %%A IN (%*) DO ---- sox location, parameters and settings
> ----- %%A "converted/%%~nA.wav"
> pause
>
> and would have to transcript this for Mac (Unix) shell (Bourne
> Shell, bash ...)
>
> I can currently make some sox Mac-shell scripts, but can't
> reproduce the above feature which allows me to drag and drop
> folders into the command line as an input, and create an output
> folder in the input files folder.

Drag and drop is a GUI feature.  So how do you drag/drop into a
command line?

The rest is practical in bash, and probably the other shells too.

> #!/bin/sh
>
> cd $~dp0
> mkdir converted

I don't really know DOS, so I don't know what directory you are
trying to change to with your "cd" command.  In bash, a tilde
expands to your home directory.

mkdir will complain if the directory already exists - unless you
use "-p" which will also create any needed parent directories.

> for A in [$*]; do

I don't like using single letter variables because they are not as
readable.  So I'm going to use "Each" instead of your "A".  But a
similar loop using the all the argument given to a command would be

for Each in $*
do sox $Each [effects, etc] converted/${Each%.*}.wav
done

The "done" at the end is necessary to close the loop.  This will
only work if there are NO spaces in any of the filenames!  The "$*"
uses spaces as the separator between input filenames.

> $$A "converted/$$~nA.wav"
>
> ' don't think I need the $$ that way but didn't find a way to
> make it work

That's is done by a bash "expansion"

${Each%.*}.wav

This strips everything after the last dot in the original name,
then adds ".wav" to the end.

> sleep
>
> ' not even sure about that one

sleep will make it pause - but you must tell it for how long.  In
just reading through, I'm not seeing why it's there...

> Any help would be greatly appreciated

man pages are great - but to can be a bit daunting.

I use bash.  I'm pretty sure most all of what I wrote will work in
any of the "shells" - not just bash.  But I often want to do bash
specific stuff in my scripts so I generally force them to bash and
not just sh.

This may not be everything you need, but it should be a start.  And
as this is question is very much an shell script question and not a
SoX question you may get more help at a shell script list or forum. *smiles*

--  fm

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

sauna-l
In reply to this post by Pander

> You could install bash via cygwin.

Well, actually I'm trying to do on a Mac what I'm doing on a PC; not the
other way round;
I can and I do run sox on Mac, but I try to translate a .bat file into a
Bourne shell one.



------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Johnny Rosenberg
2014-12-19 21:54 GMT+01:00 sauna-l <[hidden email]>:

> You could install bash via cygwin.

Well, actually I'm trying to do on a Mac what I'm doing on a PC; not the
other way round;
I can and I do run sox on Mac, but I try to translate a .bat file into a
Bourne shell one.

About dragging a file to the terminal: I have never used Mac OS X, but Bash is default in most GNU/Linux-distributions, and at least in Ubuntu I can drag a file or folder from the file manager (Nautilus) to the terminal and the location will be automatically typed into the terminal. For instance, I can type ”cd ” into the terminal and then drag my desktop from Nautilus to the terminal and the final line will look like:
~$ cd '/home/<my_user_id>/Desktop'

I'd guess that you can do the same in Mac OS X, can't you?



Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ






------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Chris Angelico
On Sat, Dec 20, 2014 at 8:46 AM, Johnny Rosenberg
<[hidden email]> wrote:
> About dragging a file to the terminal: I have never used Mac OS X, but Bash
> is default in most GNU/Linux-distributions, and at least in Ubuntu I can
> drag a file or folder from the file manager (Nautilus) to the terminal and
> the location will be automatically typed into the terminal. For instance, I
> can type ”cd ” into the terminal and then drag my desktop from Nautilus to
> the terminal and the final line will look like:
> ~$ cd '/home/<my_user_id>/Desktop'

Alternatively, if you have an executable in your file manager, you can
probably drop a file onto it and have it execute with that file as an
argument, which would be the same as Windows does (which was copied
from OS/2, although OS/2 had a flexibility that nothing since has
replicated - you can configure metadata (extended attributes) to
control the parameters, without needing an intermediate script file).

ChrisA

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

sauna-l
In reply to this post by Johnny Rosenberg

> About dragging a file to the terminal: I have never used Mac OS X, but
> Bash is default in most GNU/Linux-distributions, and at least in
> Ubuntu I can drag a file or folder from the file manager (Nautilus) to
> the terminal and the location will be automatically typed into the
> terminal. For instance, I can type ”cd ” into the terminal and
> then drag my desktop from Nautilus to the terminal and the final line
> will look like:
> ~$ cd '/home/<my_user_id>/Desktop'
>
> I'd guess that you can do the same in Mac OS X, can't you?
>

Yes, I'm doing that, like I said, you can drag & drop shell script and
paths on terminal. That's not the problem here, really, what I need,
basically, in translating the .bat file, is filling a variable with the
folder I drop.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: convert DOS bat to Bash script

Jan Stary
On Dec 20 10:15:15, [hidden email] wrote:
> Yes, I'm doing that, like I said, you can drag & drop shell script and
> paths on terminal. That's not the problem here, really, what I need,
> basically, in translating the .bat file, is filling a variable with the
> folder I drop.

No really: take the shell-scripting / drag-and-drop
discussion somewhere else.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users