Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

find index of string in shell

# 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 :: basename bash 
Shell :: git revert to last commit on remote branch 
Shell :: react native cannot load 
Shell :: nvmrc 
Shell :: Install Deno - Chocolatey (Windows) 
Shell :: how to execute .sh file in linux 
Shell :: how to remove one file from git history 
Shell :: rmdir unix 
Shell :: flutter desktop 
Shell :: generate table of content in readme.md 
Shell :: git clone with branch name command 
Shell :: delete github repository git bash 
Shell :: ros installation 
Shell :: how to update old branch 
Shell :: powershell regex 
Shell :: kubernetes get persistent volume claims 
Shell :: linux change password chpasswd 
Shell :: folder open command in linux 
Shell :: pacman search 
Shell :: statsmodels logit function 
Shell :: mac ssh download folder 
Shell :: github new repo 
Shell :: linux find and rename files with text 
Shell :: c interpreter 
Shell :: Concatenating Strings in Bash 
Shell :: get program path powershell 
Shell :: how to uninstall a package in react 
Shell :: cordova could not install from "android" as it does not contain a package.json file. 
Shell :: how to make my PS1 in linux the pwd 
Shell :: create vite app 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =