Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source From Standard In (Bash on OSX)

Tags:

bash

macos

I am trying to do something like this

 ruby test.rb | source /dev/stdin

where test.rb just prints out cd /. There are no errors, but it doesn't do anything either. If I use this:

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

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

Edit: The whole point of this is that the changes need to persist when the command is done. Sorry I didn't make that clearer earlier.

like image 476
Dan Rosenstark Avatar asked Dec 08 '22 03:12

Dan Rosenstark


2 Answers

You can try:

$(ruby test.rb)

$(...) tells bash to execute whatever output is produced by command inside ().

like image 197
mouviciel Avatar answered Jan 03 '23 10:01

mouviciel


eval `ruby test.rb`
like image 30
nobody Avatar answered Jan 03 '23 10:01

nobody