小编Ale*_*lls的帖子

警告查找:警告:您在非选项参数后指定了 -maxdepth 选项

我有这个 bash 命令:

FILES=$(find $(dirname "$DIR")/**/**/*.js -type f -maxdepth 8 -not -path "*/babel/*" -not -path "*/examples/*");
Run Code Online (Sandbox Code Playgroud)

我收到此警告:

find: 警告:您在非选项参数 -type 之后指定了 -maxdepth 选项,但选项不是位置性的(-maxdepth 影响在它之前指定的测试以及在它之后指定的测试)。请在其他参数之前指定选项。

有谁知道那是什么?谷歌一无所获。如果对我的命令还有任何疑问,请 lmk!

shell find

9
推荐指数
1
解决办法
2880
查看次数

一行环境变量设置行为

如果我这样做:

SUMAN_DEBUG=foo echo $SUMAN_DEBUG
Run Code Online (Sandbox Code Playgroud)

我没有输出

但如果我这样做:

SUMAN_DEBUG=foo && echo $SUMAN_DEBUG
Run Code Online (Sandbox Code Playgroud)

然后我得到

“富”

这是为什么?

shell bash variable-substitution variable assignment

9
推荐指数
2
解决办法
1万
查看次数

将参数附加到参数列表

我有以下 Bash 代码:

function suman {

    if test "$#" -eq "0"; then
        echo " [suman] using suman-shell instead of suman executable.";
        suman-shell "$@"
    else
        echo "we do something else here"
    fi

}


function suman-shell {

    if [ -z "$LOCAL_SUMAN" ]; then
        local -a node_exec_args=( )
        handle_global_suman node_exec_args "$@"
    else
        NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node "$LOCAL_SUMAN" --suman-shell "$@";
    fi
}
Run Code Online (Sandbox Code Playgroud)

suman用户在没有参数的情况下执行命令时,就会命中:

  echo " [suman] using suman-shell instead of suman executable.";
  suman-shell "$@"
Run Code Online (Sandbox Code Playgroud)

我的问题是 - 如何将参数附加到“$@”值?我需要简单地做一些类似的事情:

handle_global_suman node_exec_args "--suman-shell $@"
Run Code Online (Sandbox Code Playgroud)

显然这是错误的,但我不知道该怎么做。我不是 …

shell bash shell-script arguments

9
推荐指数
1
解决办法
1万
查看次数

更改命名管道的缓冲区大小

我听说对于命名管道,小于约 512 字节的写入是原子的(写入不会交错)。

有没有办法增加特定命名管道的数量?

就像是:

mkfifo mynamedpipe --buf=2500
Run Code Online (Sandbox Code Playgroud)

据说这是完整的文档:http : //www.gnu.org/software/coreutils/manual/html_node/mkfifo-invocation.html#mkfifo-invocation

man mkfifo 带我到那个页面。

fifo

8
推荐指数
1
解决办法
9224
查看次数

回勾与双引号

这个问题想了很久,还是不知道怎么查

这是:

x=`command -v r2g`
Run Code Online (Sandbox Code Playgroud)

与此相同:

x="$(command -v r2g)"
Run Code Online (Sandbox Code Playgroud)

还是和这个一样:

x=$(command -v r2g)
Run Code Online (Sandbox Code Playgroud)

...如果是后者,我应该这样做来修复它吗?

x="`command -v r2g`"
Run Code Online (Sandbox Code Playgroud)

shell-script syntax

8
推荐指数
1
解决办法
2740
查看次数

调用 shift 1 后 unshift args

我有这个场景

first_arg="$1";

if foo; then
    shift 1;
    node foo.js "$@"

elif bar; then

   shift 1;
    node bar.js "$@"

elif baz; then

   shift 1;
   node baz.js "$@"

else

   node default.js "$@"

fi
Run Code Online (Sandbox Code Playgroud)

我想把上面的变成这样:

first_arg="$1";
shift 1;

if foo; then

    node foo.js "$@"

elif bar; then

    node bar.js "$@"

elif baz; then

   node baz.js "$@"

else

   unshift 1;
   node default.js "$@"

fi
Run Code Online (Sandbox Code Playgroud)

但我不确定是否有像 unshift 这样的操作符,这是我刚刚编出来的。一种解决方法可能是这样的:

node default.js "$first_arg" "$@"
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这样做时,我得到了奇怪的行为。

shell bash arguments

8
推荐指数
3
解决办法
5543
查看次数

将 EOF 发送到命名管道 - 清理/干燥 fifo

如果我有一些从命名管道读取的随机进程:

tail -f MYNAMEDPIPED 
cat MYNAMEDPIPE | someOtherProc
Run Code Online (Sandbox Code Playgroud)

在其他地方,我可以按名称处理 MYNAMEDPIPED。是否有一种安全干净的方法可以通过删除 MYNAMEDPIPED 或以某种方式“使其变干”来停止尾部进程?

换句话说

MYNAMEDPIPED.noMoreDataIsComingThroughSoPleaseStopTailingThis()
Run Code Online (Sandbox Code Playgroud)

:)

从其中一条评论来看,它说将 EOF 发送到 MYNAMEDPIPE。但我无法弄清楚如何做到这一点。

这显示了我面临的困难:

http://comp.os.linux.questions.narkive.com/2AW9g5yn/sending-an-eof-to-a-named-pipe

pipe shell-script tail fifo

7
推荐指数
2
解决办法
8537
查看次数

`kill -9 <pid>` 和 `kill -INT <pid>` 之间的区别?

我无法弄清楚两者之间的区别

kill -9 <pid>

kill -INT <pid>

谁能像我 3 岁一样向我解释一下?

kill signals

7
推荐指数
1
解决办法
4494
查看次数

grep - 以 1 退出 - 如果匹配

我有一个像这样的 bash 函数:

run_mongo(){
  mongo foo bar baz 2>&1  # send stderr to stdout
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,如果出现错误,这个 mongo 命令不会以 1 退出,所以我必须匹配 stdout/stderr

如果有第一个匹配项,是否有某种方法可以使用 grep 以代码 > 0 退出?像这样:

run_mongo | grep -e "if stdout/stderr matches this we exit with 1"
Run Code Online (Sandbox Code Playgroud)

我假设这样做的方法是这样的:

run_mongo | grep -e "if stdout/stderr matches" | killer
Run Code Online (Sandbox Code Playgroud)

其中killer 是一个程序,它会在获得第一个stdin 后立即终止。

grep bash shell-script

7
推荐指数
2
解决办法
3655
查看次数

如果没有输入 xargs,不要让 xargs 运行该实用程序

我有这个命令:

docker volume ls -qf dangling=true | xargs docker volume rm
Run Code Online (Sandbox Code Playgroud)

我明白了:

"docker volume rm" requires at least 1 argument.
See 'docker volume rm --help'.

Usage:  docker volume rm [OPTIONS] VOLUME [VOLUME...]
Run Code Online (Sandbox Code Playgroud)

我认为这是因为没有输入xargs(因为docker命令没有返回匹配的卷)。当它没有收到任何输入时,我怎么能告诉它什么都不xargs做?

pipe xargs newlines

7
推荐指数
1
解决办法
2251
查看次数