I’m writing a shell script. A variable will have a url that will look at the the beginning few characters and
- make sure there is something before the //…so a http, https,rtmp,rtmps,rtmpe,etc….
- if nothing is in front of the // then tell user there is nothing…else if that value = whatever do whatever
How would I be able to do this?
Firstly you should should try coding this in some language such as perl or ruby that has extensive built-in regex capabilities. However if you really wish to do this in shell, then the sting operators are your friend:
url=”something://and something else”
${url%%://*} will extract “something”, i. e. the protocol being used.
${url##*://} will extract “and something else” i.e. everything to the right of ://