bash 在鱼壳中设置导出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21624512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:29:49  来源:igfitidea点击:

Setting exports in Fish Shell

bashshelldrupalfish

提问by stormpat

I have multiple versions of PHP installed, and for my normal development I always use PHP 5.5.x installed via homebrew.

我安装了多个版本的 PHP,对于我的正常开发,我总是使用通过自制软件安装的 PHP 5.5.x。

In the fish shell

在鱼壳里

 which php & php --version
=> /usr/local/bin/php
=> PHP 5.5.8 (cli) (built: Jan 16 2014 15:58:25)

The path is correct.

路径是正确的。

My problem is that when I have to develop with Drupal I use MAMP as a bundled lamp stack, and MAMP has its own php version included. My problem is that when using Drush with Drupal I cannot set the PHP executable path as I normally would in bash. I only want drush to use the bundled PHP version/executable.

我的问题是,当我必须使用 Drupal 进行开发时,我使用 MAMP 作为捆绑的灯组,并且 MAMP 包含自己的 php 版本。我的问题是,当将 Drush 与 Drupal 一起使用时,我无法像在 bash 中通常那样设置 PHP 可执行文件路径。我只想 drush 使用捆绑的 PHP 版本/可执行文件。

In bash I can do this:

在 bash 中,我可以这样做:

# Set Drush root to MAMP PHP
export DRUSH_PHP=/Applications/MAMP/bin/php/php5.5.3/bin/php

But this wont work in fish-shell, I tried with this (no success):

但这在鱼壳中不起作用,我试过这个(没有成功):

fish config location: ~/.config/fish/config.fish

鱼配置位置: ~/.config/fish/config.fish

set -x DRUSH_PHP=/Applications/MAMP/bin/php/php5.5.3/bin/php

If I run the fishshell with drush statusi always get this:

如果我运行鱼壳,drush status我总是得到这个:

 Drupal version         :  7.26
 Site URI               :  http://default
 Database driver        :  mysql
 Database username      :  root
 Database name          :  dev-db
 Default theme          :  garland
 Administration theme   :  garland
 PHP executable         :  /usr/local/bin/php
 PHP configuration      :  /usr/local/etc/php/5.5/php.ini
 PHP OS                 :  Darwin
 Drush version          :  6.2.0
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /Applications/MAMP/htdocs/Sandbox/dev
 Site path              :  sites/default
 File directory path    :  sites/default/files

And when I run the same command in bourne shell I get the correct settings:

当我在 bourne shell 中运行相同的命令时,我得到了正确的设置:

  Drupal version                  :  7.26                                        
  Site URI                        :  http://default                              
  Database driver                 :  mysql                                       
  Database username               :  root                                        
  Database name                   :  dev-db                                      
  Database                        :  Connected                                   
  Drupal bootstrap                :  Successful                                  
  Drupal user                     :  Anonymous                                   
  Default theme                   :  bartik                                      
  Administration theme            :  seven                                       
  PHP executable                  :  /Applications/MAMP/bin/php/php5.5.3/bin/php 
  PHP configuration               :  /Applications/MAMP/bin/php/php5.5.3/conf/php.ini                                       
  PHP OS                          :  Darwin                                      
  Drush version                   :  6.2.0                                       
  Drush configuration             :                                              
  Drush alias files               :                                              
  Drupal root                     :  /Applications/MAMP/htdocs/Sandbox/dev       
  Site path                       :  sites/default                               
  File directory path             :  sites/default/files                         
  Temporary file directory path   :  /Applications/MAMP/tmp/php   

So, how to set the export path to the DRUSH_PHP in fish?

那么,如何在fish中设置DRUSH_PHP的导出路径呢?

回答by Lars Blumberg

In case you want to emulate the exportcommand in your fish shell, just create the following file:

如果您想在鱼壳中模拟export命令,只需创建以下文件:

~/.config/fish/functions/export.fish

~/.config/fish/functions/export.fish

function export
    if [ $argv ] 
        set var (echo $argv | cut -f1 -d=)
        set val (echo $argv | cut -f2 -d=)
        set -g -x $var $val
    else
        echo 'export var=value'
    end
end

Launch a new terminal and then run exportfrom your fish shell as expected:

启动一个新终端,然后export按预期从您的鱼壳运行:

export foo=123
echo $foo

回答by stormpat

Derp.

德普。

The syntax was a little different, but I figured it out. Anyone having this issue, you can set an export as this:

语法有点不同,但我想通了。任何遇到此问题的人,您都可以将导出设置为:

set -x DRUSH_PHP /Applications/MAMP/bin/php/php5.5.3/bin/php

set -x DRUSH_PHP /Applications/MAMP/bin/php/php5.5.3/bin/php

and drush gets the correct PHP exec path.

并且 drush 获得正确的 PHP exec 路径。

See the setdocumentationto understand how setworks in Fish as opposed to other shells. Basically:

请参阅 set文档以了解setFish 与其他 shell 的工作原理。基本上:

set variable value