bash的别名不是一个bash功能识别:sunspot_rails,JRuby中,RSpec的 [英] bash aliases not recognized by a bash function: sunspot_rails, jruby, rspec

查看:225
本文介绍了bash的别名不是一个bash功能识别:sunspot_rails,JRuby中,RSpec的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的别名在后台运行工作太阳黑子
以下别名寻找和杀死那些实例工作
对于太阳黑子端口ENV变量是可以访问
但,
运行黑子,处理命令,杀太阳黑子功能后,才在函数外源的.bashrc工作。

$ user_id是此之前设置
在sunspot_ports()被调用,并正确打印时首测
rebash是源别名〜的.bashrc

我对开发和生产的别名,以及 - 这是刚刚重​​新presentative code

  sunspot_ports()
{
  #alias sunspot_run_test到用户的端口
  sunspot_test_port = $(($ USER_ID 5300))
  回声你太阳黑子测试端口:$ sunspot_test_port
  别名sunspot_run_test =RAILS_ENV =测试太阳黑子,Solr的运行-p $ {sunspot_test_port}&安培;
  别名sunspot_kill_test =定影-n TCP $ {} sunspot_test_port -k  出口sunspot_production_port sunspot_development_port sunspot_test_port
}solr_test()
{
  #only使得当它是函数外部别名识别
  #rebash
  没有事先的功能rebash #aliases无法识别
  sunspot_run_test
  #commands不rebash甚至认可
  #RAILS_ENV =测试太阳黑子,Solr的运行-p $ {sunspot_test_port}&安培;
  睡10;
  $ @;
  sunspot_kill_test;
  #commands不rebash甚至认可
  #定影-n TCP $ {} sunspot_test_port -k
}

我试过采购的.bashrc里面的功能,与扩展命令替换别名,并把功能sunspot_ports()在每一个组合里面。太阳黑子端口正确打印出来,当我登录的,所以我知道这code获取运行。

另外,我需要有本作中的.bashrc,而不是某个地方在我的JRuby code,因为JVM不允许分叉(否则我只想用太阳黑子,Solr的启动和太阳黑子,Solr的结束函数我的规格测试)

解决方案

bash的如果在该函数调用最初来源的时间已经定义将只解决的别名。然而,在你的情况,别名是在函数中定义的( sunspot_ports ),这功能没有被时间运行 solr_test 的来源。

您有几个选项:


  1. 调用 sunspot_ports 定义之前 solr_test

  2. 与功能,例如更换你的别名。


sunspot_kill_test()
{
   用户TCP -n $ {} sunspot_test_port -k
}

Aliases below for running sunspot in the background work Aliases below for finding and killing those instances work ENV variables for the sunspot ports are accessible But, Functions for running sunspot, processing command, and killing sunspot only work after I source .bashrc outside of the function.

$user_id is set before this sunspot_ports() gets called and prints properly when first logging in rebash is an alias for source ~.bashrc

I have aliases for development and production as well - this is just representative code.

sunspot_ports ()
{  
  #alias sunspot_run_test to the user's port
  sunspot_test_port=$(($user_id +5300))
  echo "Your sunspot test port: $sunspot_test_port"
  alias sunspot_run_test="RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
  alias sunspot_kill_test="fuser -n tcp ${sunspot_test_port} -k"

  export sunspot_production_port sunspot_development_port sunspot_test_port
}

solr_test()
{
  #only makes the aliases be recognized when it is outside the function
  #rebash
  #aliases not recognized without a rebash prior to the function 
  sunspot_run_test
  #commands not recognized even with rebash
  #"RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
  sleep 10;
  "$@";
  sunspot_kill_test;
  #commands not recognized even with rebash
  #"fuser -n tcp ${sunspot_test_port} -k"
}

I tried sourcing .bashrc inside the function, replacing the alias with the expanded command, and putting the function inside of sunspot_ports() in every combination. The sunspot port prints out correctly when I log in, so I know that this code gets run.

Also, I need to have this as a function in .bashrc instead of somewhere in my jruby code since the jvm doesn't allow forking (otherwise I would just use sunspot-solr start and sunspot-solr end in my spec tests)

解决方案

bash will only resolve the alias if it is already defined at the time that the function invoking is initially sourced. However, in your case, the alias is defined in a function (sunspot_ports), and that function has not been run by the time solr_test is sourced.

You have a couple of options:

  1. Invoke sunspot_ports before defining solr_test
  2. Replace your aliases with functions, e.g.,

sunspot_kill_test()
{
   user -n tcp ${sunspot_test_port} -k
}

这篇关于bash的别名不是一个bash功能识别:sunspot_rails,JRuby中,RSpec的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆