English 中文(简体)
撰写文稿译本
原标题:Writing an script interpreter in bash

我写了一张篮子,穿透各种设置步骤。

最基本的版本是,

   #!/bin/bash 
   #   ruby_wrapper.sh
   ruby

现在,我希望能够像正常的废墟一样利用这一包裹! 具体地说,我想创建一种使用这一“口译”的文件。

   #!/path/to/ruby_wrapper.sh
   #  my_file.rb
   puts "hello world"

因此,我希望能够做以下工作:$ /my_file.rb,而不是$、_wrapper.sh my_file.rb

这是可能的吗?

The documentation claims it isn t.

Note that the interpreter may not itself be an interpreter script.

但我看不出为什么。 是否有任何想法来解决这一问题?

最佳回答

引自您的包装,/usr/bin/env。 采用<代码>/usr/bin/envhooy的Ruby-Docs/journal/Sp/latests.pdf 由于你无需硬性规定通往<代码>ruby binary的道路,因此这不是非自然的。

$ cat ruby_wrapper.sh 
#!/bin/bash
exec ruby "$@"

$ cat wrapped.rb 
#!/usr/bin/env /tmp/ruby_wrapper.sh
puts "hello world"

$ ./wrapped.rb 
hello world

并且作为副说明,我是如何在包装稿中使用exec的。 这将使作废的口译员能够接管你的打字过程,而不是作为你的笔记的儿童过程。 这使得打字机具有透明度(例如,信号将直接投到废墟上,而不是铺面)。

问题回答

暂无回答




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签