我有这个 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!
如果我这样做:
SUMAN_DEBUG=foo echo $SUMAN_DEBUG
Run Code Online (Sandbox Code Playgroud)
我没有输出
但如果我这样做:
SUMAN_DEBUG=foo && echo $SUMAN_DEBUG
Run Code Online (Sandbox Code Playgroud)
然后我得到
“富”
这是为什么?
我有以下 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)
显然这是错误的,但我不知道该怎么做。我不是 …
我听说对于命名管道,小于约 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 带我到那个页面。
这个问题想了很久,还是不知道怎么查
这是:
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) 我有这个场景
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)
但是当我尝试这样做时,我得到了奇怪的行为。
如果我有一些从命名管道读取的随机进程:
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
我无法弄清楚两者之间的区别
kill -9 <pid>
和
kill -INT <pid>
谁能像我 3 岁一样向我解释一下?
我有一个像这样的 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 后立即终止。
我有这个命令:
docker volume ls -qf dangling=true | xargs docker volume rm
Run Code Online (Sandbox Code Playgroud)
我明白了:
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...]
我认为这是因为没有输入xargs(因为docker命令没有返回匹配的卷)。当它没有收到任何输入时,我怎么能告诉它什么都不xargs做?