Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
added 184 characters in body
Source Link
Artefacto
  • 255
  • 2
  • 11

Let's say I have a file (called e) with this content:

 a=3 b="5 6" 

How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to:

 $ env a=3 b="5 6" ruby -e 'p ENV["a"]; p ENV["b"]' "3" "5 6" $ env a=3 "b=5 6" ruby -e 'p ENV["a"]; p ENV["b"]' "3" "5 6" 

This one obviously doesn't work because of the space:

env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

But neither does this one:

IFS=$'\n' env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

And quoting $(cat e) will result in:

 "1\nb=2 3" nil 

Let's say I have a file (called e) with this content:

 a=3 b="5 6" 

How can I get each one to be interpreted as a separate argument to env? This one obviously doesn't work because of the space:

env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

But neither does this one:

IFS=$'\n' env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

And quoting $(cat e) will result in:

 "1\nb=2 3" nil 

Let's say I have a file (called e) with this content:

 a=3 b="5 6" 

How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to:

 $ env a=3 b="5 6" ruby -e 'p ENV["a"]; p ENV["b"]' "3" "5 6" $ env a=3 "b=5 6" ruby -e 'p ENV["a"]; p ENV["b"]' "3" "5 6" 

This one obviously doesn't work because of the space:

env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

But neither does this one:

IFS=$'\n' env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

And quoting $(cat e) will result in:

 "1\nb=2 3" nil 
Source Link
Artefacto
  • 255
  • 2
  • 11

Use env with environment variables from file

Let's say I have a file (called e) with this content:

 a=3 b="5 6" 

How can I get each one to be interpreted as a separate argument to env? This one obviously doesn't work because of the space:

env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

But neither does this one:

IFS=$'\n' env $(cat e) ruby -e 'p ENV["a"]; p ENV["b"]' 

And quoting $(cat e) will result in:

 "1\nb=2 3" nil