2013-02-13 110 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