【发布时间】:2021-12-20 13:30:03
【问题描述】:
我一直在尝试编写以下 bash 脚本
#!/bin/bash
python request.py $1 > output.txt
value=$(output.txt)
echo "$value"
python 代码用于执行 google 搜索并将 url 存储到输出文件。 我想打印 txt 文件,但在这里失败了。
【问题讨论】:
-
顺便说一句:我建议用
#!/bin/bash替换!/bin/bash。 -
是的,我会的!
-
当您在 shell 脚本(或 Python)中使用诸如
request.py或output.txt之类的普通文件名时,默认情况下,它们引用用户运行时所在目录中的文件脚本,不一定是脚本所在的目录。见"How can I get the source directory of a Bash script from within the script itself?"和BashFAQ #28: "How do I determine the location of my script? I want to read some config files from the same place."
标签: python bash shell sh manjaro