Skip to main content
edited tags
Link
Inian
  • 13.1k
  • 2
  • 42
  • 56
refine the question and make it clearer
Source Link
Weihang Jian
  • 1.3k
  • 2
  • 12
  • 18

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented to parse the value part.

I know there are many ways to do this by shell's feature but I want to pass literal string without shell's help (a bit like execute env by exec). That is to say, I need to find some kind of literal string format with newline and supported by env command. For example:

env FOO=LITERAL_STRING ruby -e 'puts ENV["FOO"]' 

Here the LITERAL_STRING should contain a literal string with newline and env should understand that format.

With the above command, the expected output should be:

hello world 

I wonder if it is possible. I would appreciate for your help.

Environment

  • env

    I use BSD env so it can't print the version. Don't know if man can help:

    $ man env | tail -n1 BSD April 17, 2008 BSD 
  • OS

    $ sw_vers ProductName: macOS ProductVersion: 11.6 BuildVersion: 20G165 

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented to parse the value part.

I know there are many ways to do this by shell's feature but I want to pass literal string without shell's help (a bit like execute env by exec). That is to say, I need to find some kind of literal string format with newline and supported by env command. For example:

env FOO=LITERAL_STRING ruby -e 'puts ENV["FOO"]' 

Here the LITERAL_STRING should contain a literal string with newline and env should understand that format.

With the above command, the expected output should be:

hello world 

I wonder if it is possible. I would appreciate for your help.

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented to parse the value part.

I know there are many ways to do this by shell's feature but I want to pass literal string without shell's help (a bit like execute env by exec). That is to say, I need to find some kind of literal string format with newline and supported by env command. For example:

env FOO=LITERAL_STRING ruby -e 'puts ENV["FOO"]' 

Here the LITERAL_STRING should contain a literal string with newline and env should understand that format.

With the above command, the expected output should be:

hello world 

I wonder if it is possible. I would appreciate for your help.

Environment

  • env

    I use BSD env so it can't print the version. Don't know if man can help:

    $ man env | tail -n1 BSD April 17, 2008 BSD 
  • OS

    $ sw_vers ProductName: macOS ProductVersion: 11.6 BuildVersion: 20G165 
refine the question and make it clearer
Source Link
Weihang Jian
  • 1.3k
  • 2
  • 12
  • 18

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented to parse the value part.

I know there are many ways to do this by shellshell's feature but I want to pass literal string without shell's help (a bit like execute export FOO="hello\nworld"env by exec). That is to say, I just wonder howneed to achieve the same same thing usingfind some kind of literal string format with newline and supported by env command.

Update

To make my question clearer For example:

Expected

env FOO="hello\nworld"FOO=LITERAL_STRING ruby -e 'puts ENV["FOO"]' hello world 

Actual Here the LITERAL_STRING should contain a literal string with newline and env should understand that format.

With the above command, the expected output should be:

$ env FOO="hello\nworld" ruby -e 'puts ENV["FOO"]'hello hello\nworldworld 

I wonder if it is possible. I would appreciate for your help.

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented.

I know there are many ways to do this by shell like export FOO="hello\nworld". I just wonder how to achieve the same same thing using env command.

Update

To make my question clearer:

Expected

env FOO="hello\nworld" ruby -e 'puts ENV["FOO"]' hello world 

Actual

$ env FOO="hello\nworld" ruby -e 'puts ENV["FOO"]' hello\nworld 

I mean the use of GNU env or BSD env command in the form of:

env [name=value ...] [utility [args ...]] 

Looks like there is no way to escape special characters in value part but I am not pretty sure how env is implemented to parse the value part.

I know there are many ways to do this by shell's feature but I want to pass literal string without shell's help (a bit like execute env by exec). That is to say, I need to find some kind of literal string format with newline and supported by env command. For example:

env FOO=LITERAL_STRING ruby -e 'puts ENV["FOO"]' 

Here the LITERAL_STRING should contain a literal string with newline and env should understand that format.

With the above command, the expected output should be:

hello world 

I wonder if it is possible. I would appreciate for your help.

Became Hot Network Question
added 233 characters in body
Source Link
Weihang Jian
  • 1.3k
  • 2
  • 12
  • 18
Loading
Source Link
Weihang Jian
  • 1.3k
  • 2
  • 12
  • 18
Loading