如何 cat 远程文件来读取 Bash 中的参数?
如何cat
远程文件?目前,它仅适用于本地文件。
#!/bin/bash
regex='url=(.*)'
# for i in $(cat /var/tmp/localfileworks.txt);
for i in $(cat http://localhost/1/downloads.txt);
do
echo $i;
# if [[ $i =~ $regex ]]; then
#echo ${BASH_REMATCH[1]}
#fi
done
cat: http://localhost/1/downloads.txt: 没有这样的文件或目录
How can I cat
a remote file? Currently, it works for local files only.
#!/bin/bash
regex='url=(.*)'
# for i in $(cat /var/tmp/localfileworks.txt);
for i in $(cat http://localhost/1/downloads.txt);
do
echo $i;
# if [[ $i =~ $regex ]]; then
#echo ${BASH_REMATCH[1]}
#fi
done
cat: http://localhost/1/downloads.txt: No such file or directory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
curl
:You can use
curl
:使用
wget -O- -q
代替从文件系统读取文件的cat
,它通过 HTTP 读取文档并将其写入标准输出:(
-O...
选项表示“写入指定文件”,其中-
是标准输出;-q
选项表示“安静”; ",并禁用大量日志记录,否则会导致标准错误。)Instead of
cat
, which reads a file from the file-system, usewget -O- -q
, which reads a document over HTTP and writes it to standard output:(The
-O...
option means "write to the specified file", where-
is standard output; the-q
option means "quiet", and disables lots of logging that would otherwise go to standard error.)为什么要使用 URL 从本地计算机复制?你不能直接从文件中猫吗?
如果您是从远程计算机而不是本地主机执行此操作,那么据我所知,您无法将 URL 传递给 cat。
我会尝试这样的事情:
正如其他人提到的,您也可以使用 wget 而不是 scp。
Why are you using a URL to copy from the local machine? Can't you just cat directly from the file?
If you are doing this from a remote machine and not localhost, then as far as I know you can't pass a URL to cat.
I would try something like this:
As someone else mentioned you could also use wget instead of scp.
一个简单的解决方案:
如果您不想看到curl日志:
An easy solution:
If you don't want to see the curl logs: