Using Environment Variables in Ecasound Commands
Ecasound does not natively evaluate shell environment variables
inside its internal command engine, interactive mode, or preset
configurations. Because Ecasound's parser treats command strings as
literal text, it does not expand syntax like $VARIABLE or
${VARIABLE} on its own. However, you can seamlessly use
environment variables in Ecasound workflows by relying on shell
expansion, input redirection, or external templating tools before the
commands reach the Ecasound engine.
Native Parsing Limitations
When running Ecasound in interactive mode (ecasound -c)
or executing commands from an Ecasound script file (such as with the
-s:script.eca option), the internal command parser does not
consult system environment variables.
If you issue a command containing a variable directly inside the interactive prompt:
-i:$AUDIO_DIR/input.wav
Ecasound treats $AUDIO_DIR/input.wav as a literal file
path, which causes a "file not found" error.
Method 1: Standard Command-Line Expansion
When executing Ecasound directly from a terminal shell (such as Bash, Zsh, or Dash), the shell evaluates any environment variables before passing the final arguments to the Ecasound binary.
For standard batch processing, define your variables in the shell:
export INPUT_FILE="track1.wav"
export OUTPUT_FILE="master.wav"
ecasound -i "$INPUT_FILE" -o "$OUTPUT_FILE"Because the shell expands $INPUT_FILE and
$OUTPUT_FILE prior to execution, Ecasound receives the
resolved strings.
Method 2: Dynamic Interactive Commands via Here-Strings
If you need to use interactive mode or control Ecasound via standard input while utilizing environment variables, use shell evaluation combined with pipes or here-strings:
export GAIN_VAL="5.0"
export TARGET_FILE="output.wav"
ecasound -c <<EOF
cs-add play_chain
c-add 1
ai-add input.wav
ao-add $TARGET_FILE
cop-add -ea:$GAIN_VAL
start
EOFThe shell evaluates the variables inside the <<EOF
block before feeding the resulting text stream directly into Ecasound's
standard input.
Method 3: Script
Templating with envsubst
For workflows that rely on static .eca preset scripts
where hardcoded paths are undesirable, use envsubst from
the gettext package to preprocess files before passing them
to Ecasound.
- Create a script template (
session.eca.template):
-a:1 -i:$SAMPLE_DIR/drums.wav -ea:$DRUM_VOL
-a:2 -i:$SAMPLE_DIR/synth.wav -ea:$SYNTH_VOL
-a:all -o:alsa
- Evaluate the variables and pass the generated commands to Ecasound:
export SAMPLE_DIR="/home/user/audio"
export DRUM_VOL="80"
export SYNTH_VOL="65"
envsubst < session.eca.template > session.eca
ecasound -s:session.ecaAlternatively, eliminate temporary files entirely by streaming the expanded configuration directly into Ecasound's standard input:
envsubst < session.eca.template | ecasound -cWhile Ecasound lacks a built-in variable expansion engine, these shell-level approaches provide full dynamic evaluation across both batch and real-time operations.