命令的目的是什么,什么都不做,只是一个评论领导者,但实际上是一个内置的shell?
它比在每个调用中将注释插入脚本大约40%要慢,这可能会根据注释的大小而有很大差异.我能看到的唯一可能的原因是:
# poor man's delay function
for ((x=0;x<100000;++x)) ; do : ; done
# inserting comments into string of commands
command ; command ; : we need a comment in here for some reason ; command
# an alias for `true' (lazy programming)
while : ; do command ; done
Run Code Online (Sandbox Code Playgroud)
我想我真正想要的是它可能具有的历史应用.
所以我知道有很多关于堆栈溢出的答案可以忽略 bash 脚本中的错误。不过,它们似乎都不适用于 source 命令。
我已经尝试过久经考验的 source ../bin/activate || true
我set -e在运行命令之前尝试过设置
我试过了 source ../bin/activate 2>&1 /dev/null
我set +e在运行命令之前尝试过设置。这也不起作用。
但是在这段代码的每次运行中,我都会收到
run.01: line 12: ../bin/activate: 没有那个文件或目录
这个问题的上下文是我正在创建一个运行一些 python 代码的简单 bash 脚本。指示用户如何创建特定的虚拟环境,如果他们正确设置,此行将自动激活它,否则,这应该忽略无法激活运行并在当前激活的任何环境中继续运行命令。
# Try virtual environment
source ../bin/activate || true
## Run.
code="../src-01/driver.v01.py"
## --------------------
graphInputFile="undirected_graph_01.inp"
graphType="undirected"
srcColId="0"
desColId="1"
degreeFind="2"
outFile="count.undirected.num.nodes.out"
python $code -inpGraphFile $graphInputFile -graphFormat $graphType -colSrcId $srcColId -colDesId $desColId -degreeFind $degreeFind -output_file $outFile
Run Code Online (Sandbox Code Playgroud)
无论命令是否source ../bin/activate成功,python 命令都应该执行。我有点不明白为什么这些解决方案都不起作用,目前我假设在这种情况下source可能会做一些与正常命令不同的事情。
编辑:
我#!/bin/bash -x按照要求将shebang添加到我的文件中,但这没有做任何事情。
这是我运行此脚本时的确切终端输出。 …