Skip to main content
added 271 characters in body
Source Link
Hauke Laging
  • 94.8k
  • 21
  • 132
  • 185

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

Update 1

Nearly a decade later I realize that it gets much closer than that (not sure whether it already was back then).

man -P 'less -p "^\s+set \["' bash 
set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -k 

All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.

So you can do this, too:

set -k my_script p_out='/some/path' arg_1='5' 

A bit more complicated but safer:

if [[ $- =~ k ]]; then # set -k has already been set so no need to reverse it after the command my_script p_out='/some/path' arg_1='5' else set -k my_script p_out='/some/path' arg_1='5' set +k fi 

You can test this with:

set -k echo "\$foo: '$foo'"; bash -c 'echo $foo' foo=bar 

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

Update 1

Nearly a decade later I realize that it gets much closer than that (not sure whether it already was back then).

man -P 'less -p "^\s+set \["' bash 
set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -k 

All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.

So you can do this, too:

set -k my_script p_out='/some/path' arg_1='5' 

You can test this with:

set -k echo "\$foo: '$foo'"; bash -c 'echo $foo' foo=bar 

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

Update 1

Nearly a decade later I realize that it gets much closer than that (not sure whether it already was back then).

man -P 'less -p "^\s+set \["' bash 
set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -k 

All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.

So you can do this, too:

set -k my_script p_out='/some/path' arg_1='5' 

A bit more complicated but safer:

if [[ $- =~ k ]]; then # set -k has already been set so no need to reverse it after the command my_script p_out='/some/path' arg_1='5' else set -k my_script p_out='/some/path' arg_1='5' set +k fi 

You can test this with:

set -k echo "\$foo: '$foo'"; bash -c 'echo $foo' foo=bar 
added 492 characters in body
Source Link
Hauke Laging
  • 94.8k
  • 21
  • 132
  • 185

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

Update 1

Nearly a decade later I realize that it gets much closer than that (not sure whether it already was back then).

man -P 'less -p "^\s+set \["' bash 
set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -k 

All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.

So you can do this, too:

set -k my_script p_out='/some/path' arg_1='5' 

You can test this with:

set -k echo "\$foo: '$foo'"; bash -c 'echo $foo' foo=bar 

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script 

Update 1

Nearly a decade later I realize that it gets much closer than that (not sure whether it already was back then).

man -P 'less -p "^\s+set \["' bash 
set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -k 

All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.

So you can do this, too:

set -k my_script p_out='/some/path' arg_1='5' 

You can test this with:

set -k echo "\$foo: '$foo'"; bash -c 'echo $foo' foo=bar 
Source Link
Hauke Laging
  • 94.8k
  • 21
  • 132
  • 185

The probably closest syntax to that is:

p_out='/some/path' arg_1='5' my_script