MobaXtern - 如何在 Moba 自己的 bash 终端中运行 bash shell 脚本?



问题:在Moaxterm的bash控制台中,在shell脚本中运行命令失败,而从命令行运行相同的命令。

观察:看起来在窗口内的MobaXterm终端内部运行的bash是";增强型";因此,通过一些busybox包装器,在终端中键入的命令与从终端中的脚本调用的相同命令不同。。。

示例:xargs支持命令行上的-I选项,但如果将同一命令保存在shell脚本中并执行,则会失败。。。看起来提示上的xargs是一个不同于文件本身的内置命令。。。

 27/05/2021   13:50.30   /home/mobaxterm  echo foo |xargs -I{} echo {}
foo                                                                                                                                                                                                     ✔
 27/05/2021   13:50.45   /home/mobaxterm  echo "echo foo |xargs -I{} echo {}">bar.sh
                                                                                                                           ✔
 27/05/2021   13:51.17   /home/mobaxterm  chmod 755 bar.sh
                                                                                                                           ✔
 27/05/2021   13:51.26   /home/mobaxterm  ./bar.sh
xargs: unknown option -- I
BusyBox v1.22.1 (2015-11-10 11:07:12    ) multi-call binary.
Usage: xargs [OPTIONS] [PROG ARGS]
Run PROG on every item given by stdin
-p      Ask user whether to run each command
-r      Don't run command if input is empty
-0      Input is separated by NUL characters
-t      Print the command on stderr before execution
-e[STR] STR stops input processing
-n N    Pass no more than N args to PROG
-s N    Pass command line of no more than N bytes
-x      Exit if size is exceeded
                                                                                                                           ✘
 27/05/2021   13:51.33   /home/mobaxterm  m

 27/05/2021   13:42.57   /home/mobaxterm  xargs --version
xargs (GNU findutils) 4.6.0
Packaged by Cygwin (4.6.0-1)
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
                                                                                                                           ✔
 27/05/2021   13:43.17   /home/mobaxterm  which xargs
/bin/xargs
                                                                                                                           ✔
 27/05/2021   13:43.23   /home/mobaxterm  /bin/xargs --version
xargs: unknown option -- version
BusyBox v1.22.1 (2015-11-10 11:07:12    ) multi-call binary.
Usage: xargs [OPTIONS] [PROG ARGS]
Run PROG on every item given by stdin
-p      Ask user whether to run each command
-r      Don't run command if input is empty
-0      Input is separated by NUL characters
-t      Print the command on stderr before execution
-e[STR] STR stops input processing
-n N    Pass no more than N args to PROG
-s N    Pass command line of no more than N bytes
-x      Exit if size is exceeded
                                                                                                                           ✘
 27/05/2021   13:43.28   /home/mobaxterm  

如果它确实是bash,而不是其他东西,那么最可能的解释是它的PATH设置不正确,因此它选择了"坏的";一些二进制文件的版本。要检查命令运行的实际二进制文件是什么,请使用which xargs。如果二进制文件不是您所期望的,则需要修复PATH。(如果你不知道怎么做,可以在网上搜索。(

另一种可能性是有函数/别名在跟踪二进制文件。使用command xargs ...强制shell使用命令。

我猜从那以后你已经解决了你的问题,但由于我遇到了同样的问题,我想把它发布在这里给其他人。我在moaxterm的可用软件包中搜索了xargs。

apt-get search xargs
- Found command "xargs" in package "findutils"
➤ You can install this package by using the following command:
apt-get install findutils

apt-get searchdesc xargs
- Found description "Utilities for finding files--find, xargs, locate, updatedb" in package "findutils"
➤ You can install this package by using the following command:
apt-get install findutils

安装后,它就工作了。

最新更新