Unix pipes and positional arguments

I collect sox and lame to create a new music file, but in order to do everything on one line using pipes, it seems necessary to β€œmark” the boundaries of the output and input with the help of the character. I have inherited this code, so let me show you.

 sox $DIRNAME/$BASENAME -e signed-integer -r 8000 -c 2 -t wav - trim $POSITIONS | lame -v -V4 --resample 8 - $DIRNAME/${NOEXT}.mp3 

- between wav and trim is the output file, and - between --resample 8 and $DIRNAME/${NOEXT}.mp3 is the input file.

I am trying to find additional information about this, for example, is it possible to use any character, or if - is special. What is called and what makes it work?

+4
source share
4 answers

Many Unix command line utilities use "-" as an abbreviation for "do not use the real file here, instead use stdin (or stdout)." Sox is one of these programs:

This is from the sox help system

SoX can be used in simple pipeline operations using the special filename '-', which, if used instead of the input file name, will cause SoX to read audio data from "standard input" (stdin), and if used instead of the name of the output file, will lead to that SoX sends the audio data to the "standard output" (stdout). Note that when using this option, a file type (see -t below) must also be specified.

+5
source

By convention, unix and friends use - to represent stdin and stdout.

It is not 100% universal, but it is quite widely used.

+2
source

In your example, this is the same as

 /dev/stdin 

Try replacing it - with it, you will see.

+2
source

"-" is often used as a symbol instead of a file name to say "use standard input (instead for reading) or standard output (instead of writing to a file)." This is not a feature of the shell (i.e. bash), so in this sense it is not a special character. This is a function of some commands (for example, in your case "sox" and "lame"), and it is very useful to combine these commands through channels.

+2
source

Source: https://habr.com/ru/post/1437087/


All Articles