Two less common ways to do this use the long-standing perl functions.
The first is the main Env module , which associates work environment variables with perl variables:
sh$ export VAR1=1000 sh$ export VAR2=33 sh$ perl -MEnv -E 'say $VAR1/$VAR2'
Note that variables must be present in the environment inherited by the perl process, for example, export VAR , as described above, or explicitly for a single command (as in FOO=hello perl -MEnv -E 'say $FOO' ).
A second and more obscure way is to use perl -s switch to set arbitrary variables from the command line:
sh$ VAR1=1000 sh$ VAR2=33 sh$ perl -s -E 'say $dividend/$divisor' -- -dividend=$VAR1 -divisor=$VAR2 333.333333333333
awk does something similar with its -v switch .
source share