简体   繁体   English

从Scala代码执行的Shell命令无法识别bash别名

[英]Shell command executed from scala code not recognizing bash alias

I have a scala file that executes a hdfs command similar to this: 我有一个scala文件,该文件执行类似于以下内容的hdfs命令:

hdfs dfs -mkdir /test/

The command runs fine when I run it in my shell because I have the following alias set in my .bashrc file: 在shell中运行命令时,该命令运行良好,因为在.bashrc文件中设置了以下别名:

alias hdfs='/usr/local/hadoop-2.7.0/bin/hdfs'

...however when I build the code that runs the shell command in my Scala code using SBT I get the following error: ...但是,当我使用SBT构建在Scala代码中运行shell命令的代码时,出现以下错误:

 java.io.IOException: Cannot run program "hdfs": error=2, No such file or directory

Is there a way for the alias to be recognized? 有什么办法可以识别别名? I cannot change the code because I want the program to run on any system with hdfs installed, no matter the directory, the only thing that should change is the alias. 我无法更改代码,因为我希望程序在安装了hdfs的任何系统上运行,无论目录如何,唯一需要更改的就是别名。

Futher information: I'm running my test in a docker image with hadoop (shouldn't change anything), the image runs a script that executes the following two lines every time the container starts up: 进一步的信息:我正在使用hadoop在docker映像中运行测试(不应更改任何内容),该映像运行一个脚本,该脚本在每次容器启动时执行以下两行:

source ~/.bashrc         # To get the alias
shopt -s expand_aliases  # To allow alias expansion in your script

在我的.bashrc文件中的以下行已修复

export PATH=$PATH:/usr/local/hadoop/bin/

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

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