Source from standard input (Bash on OSX)

I'm trying to do something like this

 ruby test.rb | source /dev/stdin

where test.rb just prints cd /. There are no errors, but he does nothing. If I use this:

 ruby test.rb > /tmp/eraseme2352; source /tmp/eraseme2352

It works fine, but I want to avoid the intermediate file.

Change: . The thing is that changes must be saved when the command is executed. Sorry, I have not done this more clearly before.

+3
source share
6 answers

You can try:

$(ruby test.rb)

$(...)tells bash to execute any output created by the command inside ().

+6
source
eval `ruby test.rb`
+3
source

, bash , :

for c in `ruby test.rb` ; do $c ; done

. , . !

+2

Mac OS X 10.6.7:

/bin/bash

sw_vers   # Mac OS X 10.6.7

bash --version   # GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)

source /dev/stdin <<<'echo a b c'

source /dev/stdin  <<< "$(ruby -e 'puts "echo a b c"')"

source /dev/stdin <<<'testvar=TestVal'; echo $testvar


source /dev/stdin <<-'EOF'
echo a b c
EOF

source /dev/stdin <<-'EOF'
$(ruby -e 'puts "echo a b c"') 
EOF

(
source /dev/stdin <<-'EOF'
testvar=TestVal
EOF
echo $testvar
)
+2

bash ( sh):

while read -a line
do
  "${line[@]}"
done < <(somescript)

The spaces in the arguments to the commands must work with a backslash to work.

+1
source

How about just

ruby test.rb | bash
0
source

Source: https://habr.com/ru/post/1739764/


All Articles