Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

find the index of a substring

# To find the index of a substring in another string
# Take for instance, below take two strings: str and substr. 

str="hello world"
substr="world"
 
prefix=${str%%$substr*}
index=${#prefix}
 
if [[ index -eq ${#str} ]];
then
    echo "Substring is not present in string."
else
    echo "Index of substring in string : $index"
fi

Comment

PREVIOUS NEXT
Code Example
Shell :: bash index of string 
Shell :: mount a folder from windows inside wsl 
Shell :: mac terminal wifi commands 
Shell :: git rename other branch 
Shell :: renaming branch in git 
Shell :: how to pass docker hub credentials for k8s pods 
Shell :: insert image into github wiki 
Shell :: $() vs () bash 
Shell :: pytest_check 
Shell :: uninstall editable pip 
Shell :: move all subfolders to parent folder linux 
Shell :: ssh login without passowrd 
Shell :: swagger editor locally 
Shell :: grep usage 
Shell :: sed mac install 
Shell :: install magento 2 docker 
Shell :: vim brew 
Shell :: git merge conflict resolve 
Shell :: command to install any package using Pip 
Shell :: For which GitHub repository would you like to set up a GitHub workflow? 
Shell :: running docker image 
Shell :: yum install redis cli 
Shell :: gitgraken pre-receive hook declined 
Shell :: open crontab in nano 
Shell :: powershell and command 
Shell :: set git remote heroku to https://git.heroku.com/resume-projects.git 
Shell :: shell pipe 
Shell :: habe to install viber on linux 
Shell :: ubuntu 20.4 uninstall cloud image 
Shell :: xp_cmdshell bcp 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =