Home > Back-end >  How to extract protocols (http)[s] to check url using shell script
How to extract protocols (http)[s] to check url using shell script

Time:08-20

I have tried below one:


A=https://xyz.site
echo -e ${A//:*}

Result: https


Please describe me that, how this ${A//:*} term results https or http and what's the concept behind it, share a article or pdf if possible.


For Worldwide web [www]

Its preety simple to extract this one:


A=www.google.com
echo -e ${A::3}

Result: www

CodePudding user response:

${parameter:offset:length} — This is referred to as Substring Expansion. In your example ${A::3} means ${A:0:3} and returns the first 3 characters of the variable A.

${parameter/pattern/string} — This notation replaces the first match of pattern with a string. If pattern begins with /, all matches of pattern are replaced with string. In your example ${A//:*} means ${A//:*/} and it replaces all patterns :* with an empty string.

  • Related