在浏览器上打印字符串,shell脚本

时间:2017-05-17 19:28:52

标签: bash shell

我无法找到在浏览器中打印shell脚本中的字符串的命令。例如,在stackoverflow上。我想创建一个脚本,在搜索栏中写一个字符串并搜索

xdotool mousemove x y # position of the searchbar
xdotool mouseclick 1 # leftclick
[[command that writes a string on the searchbar]]
xdotool key KP_Enter # press enter

应该很容易,但我无法找到它

2 个答案:

答案 0 :(得分:0)

可能有一种近似的方式来做你想要的(在Linux Debian 8中测试)。您可以 - 作为普通用户,而不是root(see this) - 运行以下命令(在终端上):

firefox "http://stackoverflow.com/search?q=my_search_term"

这将在Stack Overflow页面上打开firefox,该页面将显示术语my_search_term的搜索结果。

如果您需要在运行为root的脚本上运行此代码,则仍然可以(安全地)运行此命令,如果您将其作为“普通”用户而不是{{1例如:

root

要找出谁应该用于运行上述命令的su - myuser -c 'firefox "http://stackoverflow.com/search?q=my_search_term"' ,最好的选择之一是使用user命令,例如:

logname

注意:此类解决方法也适用于许多其他网站,例如Google,只需替换为正确的myuser="$(logname 2>/dev/null)" 地址,例如:

url

答案 1 :(得分:-1)

这个question的回答是否有用?只需使用适当的搜索字符串 https://stackoverflow.com/search?q=foobar

替换url即可
相关问题