我正在尝试创建一个对多个错误源具有健壮性的snakemake流水线。我想在我的管道中调用一个bash脚本。提醒用户注意问题的一个标准过程是在bash脚本的开头使用以下内容:
#!/bin/bash
set -e
set -u
set -o pipefail
当使用管道将std重定向出时,pipefail会检查错误。我的脚本中有以下几行简单的代码
# Read the first argument
input=$1
less $input | head -10
当我在终端中直接使用运行我的脚本时
bash script.sh input
它运行得很好,没有检测到错误。
然后,我希望在如下规则
几天前,我就开始学习如何在shell中编写脚本。如何使脚本thaht获得两个参数(文件名和某个目录),如果参数不好,我想发出错误警报,如果它们是正确的,我希望在给定目录中复制文件。到目前为止我做了这个:
#!/bin/bash
if [ -d $1 ] ; then
???
done
else
echo $1 NOT DIRECTORY
exit 1
fi
另外,我做了一个检查文件的部分。怎么把这些放在一起?
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Use- $0 file"
exit 1
fi
if [ -f $1 ]
the
我目前正在编写一个小型bash脚本,以便在特定位置创建一个预填充的文件。为此,bash脚本调用vim并执行vim脚本。在这个vim脚本中,我想问用户要保存创建的文件的位置是否正确。然后用户输入“是”或“否”。为此,我将使用以下命令:
call inputsave()
let name = input('Is it the correct location ? y/n')
call inputrestore()
当我使用gvim或vim时,这个输入函数工作得很好。但是从一个脚本中,没有显示什么是我启动bash脚本的终端。
有没有办法将输出重定向到我的终端?
我找到了:redir
解释起来有点困难,但我正在寻找一个相对简单的bash脚本,如果它找不到一个名称与mp4相同的文件,就可以删除它。
基本上,我有这样的文件:
S01E02 - Name of Episode 2.description
S01E02 - Name of Episode 2.srt
S01E02 - Name of Episode 2.mp4
S01E03 - Name of Episode 3.description
S01E03 - Name of Episode 3.srt
S01E03 - Name of Episode 3.mp4
S01E04 - Name of Episode
我有一个shell脚本,我需要在容器中运行,这个容器通常安装了bash。但是,我希望迁移这个容器,使其不受影响,只想在容器中安装最必要的二进制文件和工件。
我有一个基本的shell脚本,下面是其中的一个片段:
#! /usr/bin/env bash
function _process_msg() {
if [[ -n "${SCRIPT_MSG}" ]]; then
echo -e "\e[32mDEBUG: $1\e[39m" >&2
for text in "$@"; do
echo -e
根据的说法,使用set -e内置应该足以让bash脚本在第一个错误时退出。然而,下面的脚本:
#!/usr/bin/env bash
set -e
echo "a"
echo "b"
echo "about to fail" && /bin/false && echo "foo"
echo "c"
echo "d"
指纹:
$ ./foo.sh
a
b
about to fail
c
d
删除echo "foo" 会停止脚本,但为什么呢?
具有以下bash脚本:
#!/bin/bash
set -e
function foo() {
# commands that might fails and I want to exit my script
...
echo "result I need as output"
}
my_var=$(foo)
echo "I don't want this if there is an error inside foo"
使用set -e (在bash 4.4.19中)似乎不适用于子still,即仍然在执行最后一个echo命令)。如果
以下带有调试选项“set -e -v”的脚本仅在变量的先前值为零时才在增量运算符处失败。
#!/bin/bash
set -e -v
i=1; let i++; echo "I am still here"
i=0; let i++; echo "I am still here"
i=0; ((i++)); echo "I am still here"
bash (GNU bash,版本4.0.33(1)-release (x86_64-apple-darwin10),但也包括GNU bash,版本4.2.4(1)-release (x86_6
我试图通过添加一些错误捕获来修复bash脚本。我有一个文件(list.txt),其内容通常如下:
People found by location:
person: john [texas]
more info on john
有时,该文件被破坏,并且它只有第一行:
People found by location:
我正在试图找到一种方法来检查该文件,以查看第2行中是否存在任何数据,我希望将其包含在bash脚本中。这个是可能的吗?
我在Ubuntu10.04服务器上设置了一个bash脚本,每当在该服务器上的./incoming/目录中创建新的PDF时,都会在./outgoing/文件夹中创建新的PDF。这两个文件夹都在本地计算机上,并与samba版本3.4.7共享。该脚本使用inotifywait监视传入目录(根据)。
inotifywait -m ./incoming/ -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory &
我有一个shell脚本,它调用Perl脚本来执行一些文件处理。Perl脚本以零或一个值退出。如果Perl脚本的值为1,则在脚本开头有Unix set -e命令来中止该脚本。我只是在想,如果Perl脚本以一个值退出,那么在脚本中止之前是否可以使用Unix中的任何命令来执行一个命令?本质上,我希望脚本向我发送一封电子邮件,说明Perl脚本是否成功运行。我的代码现在看起来是这样的:
#!/bin/bash
set -e
function email_success {
#Some code for the email
}
function email_fail {
#Some code fo
我最近读了一篇名为"Tag a Repo from a Jenkins Workflow Script“的文章,我的问题与此非常相似,但使用的是bash脚本(而不是工作流脚本)。
在我的脚本中,我有
#!/bin/bash
...
git push origin :refs/tags/${NEW_TAG}
git tag -fa $NEW_TAG
git push origin master --tags
但一开始我得到的是"git“命令
fatal: could not read Username for 'https://github.com': No
我必须激活虚拟环境(venv),所以我在终端中手动运行以下命令: source .venv/bin/activate # To activate the virtual env. 和 deactivate # To deactivate the virtual env 这在手动运行时工作得很好。现在,我必须将这些命令插入到bash脚本中,以使AWS CodeDeploy能够将其部署到Ubuntu18.04服务器上。 我的名为after_install.sh的bash脚本如下所示... #!/usr/bin/env bash
set -e
sou