2013-02-13 111 views
2

我正在与厨师和红宝石,我试图运行set命令。Ruby:试图运行设置命令

setVarList = %x(set) 

如果我只需键入设置它工作正常,但如果我运行此脚本,我得到以下错误:

/var/chef/cache/cookbooks/motd/recipes/default.rb:22: command not found: set 

有什么不对?

+2

'setVarList =%x(/ bin/bash -c set)' – 2013-02-13 17:15:40

回答

3

正如Anew已经提到的:设置被bash的内置命令,但红宝石%×()壳是SH

%x(echo $0) 

解决方法是运行bash明确,在意见提出CodeGnome

%x(/bin/bash -c set) 
2

看起来你不会产生bash shell。

set是一个bash内置:

4.3.1 The Set Builtin

This builtin is so complicated that it deserves its own section. set allows you to change the values of shell options and set the positional parameters, or to display the names and values of shell variables.

set 
set [--abefhkmnptuvxBCEHPT] [-o option-name] [argument …] 
set [+abefhkmnptuvxBCEHPT] [+o option-name] [argument …] 

If no options or arguments are supplied, set displays the names and values of all shell variables and functions, sorted according to the current locale, in a format that may be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In POSIX mode, only shell variables are listed.

http://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

尝试运行ps -p $$看哪个壳是越来越催生。

[email protected]:~$ ps -p $$ 
    PID TTY   TIME CMD 
10018 ttys001 0:00.11 -bash 
[email protected]:~$ 
+0

感谢您的宝贵信息!如果我可以放弃,你会有一个。 – user2068979 2013-02-14 09:12:10