Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does bash recognize a link?

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
like image 924
Roxana Ciobanu Avatar asked Nov 24 '13 13:11

Roxana Ciobanu


1 Answers

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

  • 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.

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

where how to open webpage is described e.g. here.

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.

like image 84
Mateusz Kubuszok Avatar answered Oct 03 '22 18:10

Mateusz Kubuszok