Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 从scala代码执行的Shell命令无法识别bash别名_Linux_Bash_Sbt - Fatal编程技术网

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

Linux 从scala代码执行的Shell命令无法识别bash别名,linux,bash,sbt,Linux,Bash,Sbt,我有一个scala文件,它执行与以下类似的hdfs命令: hdfs dfs -mkdir /test/ 在shell中运行该命令时,该命令运行正常,因为在.bashrc文件中设置了以下别名: alias hdfs='/usr/local/hadoop-2.7.0/bin/hdfs' …但是,当我使用SBT在Scala代码中构建运行shell命令的代码时,我得到以下错误: java.io.IOException: Cannot run program "hdfs": error=2, No

我有一个scala文件,它执行与以下类似的hdfs命令:

hdfs dfs -mkdir /test/
在shell中运行该命令时,该命令运行正常,因为在.bashrc文件中设置了以下别名:

alias hdfs='/usr/local/hadoop-2.7.0/bin/hdfs'
…但是,当我使用SBT在Scala代码中构建运行shell命令的代码时,我得到以下错误:

 java.io.IOException: Cannot run program "hdfs": error=2, No such file or directory
有办法识别别名吗?我无法更改代码,因为我希望程序在安装了hdfs的任何系统上运行,无论目录如何,唯一应该更改的是别名

进一步资料: 我正在使用hadoop在docker映像中运行测试(不应更改任何内容),该映像运行一个脚本,该脚本在每次容器启动时执行以下两行:

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

修复了my.bashrc文件中的以下行

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

@hek2mgl不,我已经看过并尝试了他们的解决方案(包括在我的答案中),它们不起作用,所以我假设问题不同。如果您将shell作为交互式shell启动,它将读取~/.bashrc并允许使用别名:
bash-I'hdfs dfs-mkdir/test/'