问题描述
说我有在包含脚本的URLhttp://mywebsite.com/myscript.txt的文件:
#!/斌/庆典
回声你好,世界!
阅读-p你叫什么名字?名称
回声你好,$ {name}的!
和我想不先保存到一个文件运行此脚本。我该怎么做呢?
现在,我见过的语法:
庆典< ≤(卷曲-s http://mywebsite.com/myscript.txt)
但这似乎并不像它想如果我保存到一个文件,然后执行工作。例如readline的不工作,并且输出仅仅是:
$庆典< ≤(卷曲-s http://mywebsite.com/myscript.txt)
你好,世界!
同样,我已经试过:
卷曲-s http://mywebsite.com/myscript.txt |庆典-s -
使用相同的结果。
我本来喜欢一个解决方案:
时间戳=`日期+%Y%M%D%H%M%S`
卷曲-s http://mywebsite.com/myscript.txt -o /tmp/.myscript.${timestamp}.tmp
庆典/tmp/.myscript.${timestamp}.tmp
RM -f /tmp/.myscript.${timestamp}.tmp
但这似乎邋遢,我想一个更好的解决方案。
我知道关于从URL运行shell脚本的安全问题,但让我们忽略了这一切的现在。
来源≤(卷曲-s http://mywebsite.com/myscript.txt)
应该这样做。另外,离开了你们都要初始重定向,这是重定向标准输入; 庆典
将文件名不进行重新定向到执行就好了,和≤(命令)
语法提供了一个路径。 p>
庆典≤(卷曲-s http://mywebsite.com/myscript.txt)
(猫的/ dev / null的)
如果你看看 Say I have a file at the URL "http://mywebsite.com/myscript.txt" that contains a script: And I'd like to run this script without first saving it to a file. How do I do this? Now, I've seen the syntax: But this doesn't seem to work like it would if I saved to a file and then executed. For example readline doesn't work, and the output is just: Similarly, I've tried: With the same results. Originally I had a solution like: But this seems sloppy, and I'd like a more elegant solution. I'm aware of the security issues regarding running a shell script from a URL, but let's ignore all of that for right now. ought to do it. Alternately, leave off the initial redirection on yours, which is redirecting standard input; It may be clearer if you look at the output of 这篇关于从URL执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!回声&LT的输出可能更清晰
#!/bin/bash
echo "Hello, world!"
read -p "What is your name? " name
echo "Hello, ${name}!"
bash < <(curl -s http://mywebsite.com/myscript.txt)
$ bash < <(curl -s http://mywebsite.com/myscript.txt)
Hello, world!
curl -s http://mywebsite.com/myscript.txt | bash -s --
timestamp=`date +%Y%m%d%H%M%S`
curl -s http://mywebsite.com/myscript.txt -o /tmp/.myscript.${timestamp}.tmp
bash /tmp/.myscript.${timestamp}.tmp
rm -f /tmp/.myscript.${timestamp}.tmp
source <(curl -s http://mywebsite.com/myscript.txt)
bash
takes a filename to execute just fine without redirection, and <(command)
syntax provides a path.bash <(curl -s http://mywebsite.com/myscript.txt)
echo <(cat /dev/null)