我在执行此脚本时收到此错误
-bash: ./conn.sh: /usr/bin/bash: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这是一个Linux系统(Ubuntu)
我有一个运行的脚本
python3 /path/script.py
Run Code Online (Sandbox Code Playgroud)
我不知道如何使脚本在启动时运行。
任何指点都会很棒!
直接在命令行上,这有效:
$sed "s/a/X/;s/X/&a&/" file
Run Code Online (Sandbox Code Playgroud)
使用 shell 变量也是如此:
$varin=a ; varout=X ; sed "s/$varin/$varout/;s/$varout/&$varin&/" file
Run Code Online (Sandbox Code Playgroud)
但是使用外部脚本文件
$sed -f script.sed file
Run Code Online (Sandbox Code Playgroud)
只有“硬编码”方法才有效
$cat script.sed
s/a/X/
s/X/&a&/
Run Code Online (Sandbox Code Playgroud)
虽然 shell 变量没有扩展
$cat script.sed
s/$varin/$varout/
a/$varout/&$varin&/
$varin=a ; varout=X ; sed -f script.sed file
#-> variables in script.sed not interpreted; output unchanged
Run Code Online (Sandbox Code Playgroud)
如何实现外部脚本文件中shell变量的解释sed?
我很明白它sed本身无法解释 shell 变量,但是我如何预处理脚本(以保存方式)以一次运行它来bash解析变量?sed也许人们可以在一开始就使用命令将它们导入?
以下方法没有成效(使用bash):
export varin=a ; export varout=Xsed -e $(cat sed.script) file:适用于单行脚本,在多行脚本上失败,即使注释作为第一行sed -f <(cat script.sed) file …我制作了一个bash包含命令的 shell 脚本while,但是当我在终端上使用命令运行脚本时source,它给出了语法错误消息。
我需要使用source,因为我必须在终端上设置环境变量,没有source.
echo $shell给出:/bin/csh
shell 不是给出
的交互式输出ps -p $$CMD : tcsh
脚本是:
#! /bin/bash
i=1
while read line
do
echo "$line $i"
echo
i=$((i+1))
done < seed.txt
Run Code Online (Sandbox Code Playgroud)
错误是:
i=1: Command not found.
while: Expression Syntax.
Run Code Online (Sandbox Code Playgroud) 为什么 += 在脚本中用作串联?
while read t
do
t+=2
echo $t
Run Code Online (Sandbox Code Playgroud)
我在末尾添加了 2...为什么?
我正在尝试提取脚本中响应URL中返回的一部分。这将在脚本的后期阶段使用。curlbash
卷曲响应具有以下 URL:
https://www.example.com/1234/text/111?x=999988
Run Code Online (Sandbox Code Playgroud)
现在,我想text/111?x=999988从中提取。另外,我只想将数字存储111在变量中。我正在尝试这样做
#!/bin/bash
sample_link="https://www.example.com/1234/text/111?x=999988"
sample_extract=${sample_link##*/}
echo "$sample_extract"
Run Code Online (Sandbox Code Playgroud)
但这只给了我111?x=999988
谁能告诉我我缺少什么以及如何解决它?
PS:如果缺少任何信息,请告诉我
我有一个 python 函数,它接受一个参数作为输入,我想自动化并通过 bash 调用它。但是当我在调用它时传递变量(字符串)时,bash 给出错误
a="test"
python -c "from pipeline_runs.z_full_pipeline import test; test($a)"
Run Code Online (Sandbox Code Playgroud)
失败了
NameError: name 'test' is not defined
Run Code Online (Sandbox Code Playgroud)
但当变量为 int 时,效果相同
a="10"
python -c "from pipeline_runs.z_full_pipeline import test; test($a)"
Run Code Online (Sandbox Code Playgroud)
当第一个代码失败时它会运行。任何人都可以解释为什么会出现这样的行为,以及我应该更改什么才能将字符串从 bash 脚本传递到 python 函数
我需要提取一些目录树中有多少文件的信息:
/.../testRoot/test1/test11/..../file1
/.../testRoot/test1/test11/file2
/.../testRoot/test1/test11/..../file3
/.../testRoot/test1/test11/file4
.....................................
/.../testRoot/test1/test1n/fileq
/.../testRoot/test1/test1n/..../filew
/.../testRoot/test1/test1n/filee
/.../testRoot/test1/test1n/.../.../ .../filer
Run Code Online (Sandbox Code Playgroud)
如何计算testRoot中有多少个文件?
我想简单地0.050在 bash 脚本中重新分配一个变量(具体来说,将其增加)。在我编写的以下脚本中,i是(整数)索引,mytime是十进制/双精度/浮点数。“ps”(皮秒)是我在计算中使用的时间单位。
#!/bin/bash
mytime = 0.000
for i in {1..3}
do
echo "$i: $mytime ps"
mytime = mytime + 0.050
done
Run Code Online (Sandbox Code Playgroud)
但是,当我使用 运行此脚本时bash test.sh,会收到以下错误消息:
test.sh: line 2: mytime: command not found
1: ps
test.sh: line 6: mytime: command not found
2: ps
test.sh: line 6: mytime: command not found
3: ps
test.sh: line 6: mytime: command not found
Run Code Online (Sandbox Code Playgroud)
为什么它似乎被解释mytime为命令或函数,而不是变量?你能帮我纠正这个吗?
你能帮我解决以下问题吗?
任何人都请提出自动化上述步骤的想法。我可以做第一步和第三步,但我不知道第二步:(