[英]Can I create a bash script that relies on the exit code from the previously executed command in my shell?
[英]Shell command executed from scala code not recognizing bash alias
我有一个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
在我的.bashrc文件中的以下行已修复
export PATH=$PATH:/usr/local/hadoop/bin/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.