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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 求fpga交通信号灯设计Verilog代码
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头