doufan1363 2018-03-01 23:41
浏览 211

在GoLang中执行bash shell函数?

We have a large collection of shell functions for various uses that are added to our .bash_profiles and we use on a daily basis. We call the functions like regular binaries.

I am trying to call these same shell functions from inside a GoLang app but it cannot find them as it's obviously running in a different context and can't find these in my $PATH.

The error is: exec: "finderx": executable file not found in $PATH

Does anyone know how to execute shell commands from a GoLang app in the same context as the terminal it's running in? or maybe to re-source them some how I don't want to have to re-implement these functions if possible.
I'd like to just call them as we do from scripts to ease the transition period. We will be gradually moving everything across to Go, but for now, we have to live with the shell functions

  • 写回答

2条回答 默认 最新

  • dounai7148 2018-03-02 01:51

    I guess you can simply invoke bash -l -c 'your alias function'. Just make sure that your .bash_aliases or another dotfile with your functions is sourced from .bashrc(which, by the way, should be sourced from .bash_profile, as non-interactive login shell doesn't read .bashrc).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 echarts如何对X轴进行分组
  • ¥15 维纳滤波器的实验题及计算机实现,求解
  • ¥15 fluent模拟静态气体扩散
  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,别用人工智能回答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做