简体   繁体   English

从symlink目录运行带有相对路径的命令

[英]Run a command with relative path from symlink directory

I've got a directory structure like this: 我有一个这样的目录结构:

bin
  drush
build -> vendor/drupal/core
vendor
  drupal
    core

So as you see, build is a symlink to the core directory. 如您所见, build是到core目录的符号链接。 drush is an executable file. drush是一个可执行文件。 I need to be able to cd into build and call drush from there. 我需要能够以cdbuild和呼叫drush从那里。

But if I do this: 但是,如果我这样做:

cd build
../bin/drush

This doesn't work, because .. points to vendor/drupal directory, because when I cd into build , it in fact goes to vendor/drupal/core , of course. 这是行不通的,因为..指向vendor/drupal目录,因为当我cd进入build ,实际上它进入了vendor/drupal/core

I know I can call it this way: ../../../bin/drush , but is there some kind of workaround to make .. point to the root, not the actual parent? 我知道我可以这样称呼它: ../../../bin/drush ,但是是否有某种解决方法可以使..指向根目录,而不是实际的父目录?

You can create an another symlink in the folder "drupal" on the executable drush. 您可以在可执行文件drush的“ drupal”文件夹中创建另一个符号链接。 So with this way, you can call it from "build". 这样,您可以从“构建”中调用它。

$ cd vendor/drupal/
$ ln -s absolute_path/bin/drush dummy-drush 
$ cd build 
$ ./dummy-drush

Solution 1 : If you don't want to create anything in vendor, maybe it's better to create an alias which allows to you to execute drush (be careful to give the good path). 解决方案1:如果您不想在供应商中创建任何东西,也许最好创建一个别名,以允许您执行drush(小心给出正确的路径)。

Solution 2 : 解决方案2:

If the directory bin in your example is not the folder "/bin" from the root, you can add it in your PATH in order to execute every executable . 如果示例中的目录bin不是根目录中的文件夹“ / bin”,则可以将其添加到PATH中以执行每个可执行文件。

$ export PATH=$PATH:/personal_bin/
$ cd bin
$ ln -s drush dummy-drush 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM