bash如何识别链接? [英] How does bash recognize a link?

查看:105
本文介绍了bash如何识别链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个捕获href链接的bash脚本中,bash如何知道TEXT是链接而不是典型的字符串?为什么在$ TEXT =www.google.com结束时,TEXT仍然是一个链接?你能用文件做到吗?例如,有一个点击我运行一个脚本。

In a bash script that captures a href link, how does bash know that TEXT is a link and not a typical string? Why at the end when $TEXT="www.google.com", TEXT is still a link? Can you do that with a file? For example having a 'Click me' that runs a scrip.

shopt -s nocasematch

TEXT='<a href="http://www.google.com/search/something/lulz/here2 i=!mfo1iu489fn1o2jlk21m4098mdoi">"test link"</a><br>'

TEXT=${TEXT##*href=\"}
TEXT=${TEXT%%\"*}
TEXT=${TEXT##*//}
TEXT=${TEXT%%/*}

echo $TEXT


推荐答案

我会说bash本身不识别链接。但是当您输入 echo http://www.google.com <时,某些终端模拟器会在gnome终端中

I'd say that bash itself doesn't recognize links. But some terminal emulators does


  • / code>或'echo www.google.com'终端允许您点击链接,但 echo google.com 将不会被识别为一个 - 它最有可能取决于 http:// 前缀(清楚地表明它是一个链接)或 www 前缀(通常发生在www地址),

  • E17的术语类似于gnome teminal在这方面的行为,

  • 可能大多数其他终端模拟器都会以类似的方式行事,但是我可以确认。

  • in gnome terminal when you type echo http://www.google.com or 'echo www.google.com' terminal with allow you to click on link, but echo google.com will not be recognized as one - it most likely depends on http:// prefix (clearly indicating that it's a link) or www prefix (often occurring at www adress),
  • E17's terminology act similarly it gnome teminal in this regard,
  • probably most other terminal emulators will act in a similar manner, but that 2 I can confirm.

从bash脚本的使用方式我会说没有与实现无关的方法来添加可点击的URL进入bash。但是您可以使用描述的方式在终端仿真器中获得类似的行为。或者,从用户处获得一些yes-no变量,并在条件程序调用中使用它:

From how bash scripts are used I'd say that there is no implementation independent way to add clickable URLs into bash. But you can used described way to obtain similar behavior in terminal emulators. Alternatively, obtain from user some yes-no variable, and use it in conditional program call:

read openpage
if $openpage -eq "yes"
  # open browser with your URL
fi

例如,如何打开网页此处

至于文件,如果是$ runfile -eqyes那么我将只用命令;网络。基本上bash并没有考虑任何GUI交互 - 毕竟它是终端。

As for the files, I'd stay with just if $runfile -eq "yes" then command; fi. Basically bash wasn't made with any GUI interaction on mind - it's a terminal after all.

这篇关于bash如何识别链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆