# String Operations In Shell Scripting

### Operations On String In Shell Script

\-&gt; On the **string we can perform multiple operations** which we are going to see -

**\-&gt; Suppose we want to find the Length of the String then -**

```plaintext
#!/bin/bash
myVar="String Operations"

stringLength=${#myVar} # It will find the Length of the string

echo "Length of the string is - $stringLength"
```

Output -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691659623032/2dc5c847-409c-43f1-b59e-03a391d58379.png align="left")

**To Convert all Letters in Upper Case -**

```plaintext
#!/bin/bash
myVar="String Operations"

upperCaseVariable=${myVar^^} # It will convert all the letters into upper case

echo "Upper Case is - $upperCaseVariable"
```

Output -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691660011996/6acecb41-4aca-408a-92a6-88ffffe7cac1.png align="left")

**To convert all Letters in Lower Case -**

```plaintext
#!/bin/bash
myVar="String Operations"

lowerCaseVariable=${myVar,,} # It will convert all the letters into lower case

echo "Lower Case is - $lowerCaseVariable"
```

Output -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691660194693/71b25fc9-da46-4ba7-ac71-c942f32dda80.png align="left")

**To replace a word with another word -**

```plaintext
#!/bin/bash
myVar="String Operations"

replaceWord=${myVar/String/ReplacedString} # First of all we have to give name of the variable and then string that we want to replace and then the values by whic we want to replace

echo "New variable is - $replaceWord"
```

Output -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691660487497/1ea70691-81fd-4373-b3d3-052ce0941d53.png align="left")

**Slicing of the String -**

\-&gt; Suppose we want to get some part of the sentence then with the help of a string slice we can achieve this -

```plaintext
#!/bin/bash
myVar="String Operations"

stringSlice=${myVar:3:7} # To  get the word from 3 character number to 7 characters i.e. start from 3 character and take 7 characters

echo "In a myVar Variable from 3rd charcter and total should be 7 characters is - $stringSlice "
```

Output -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691661457162/64b774ea-3f78-4d20-9278-1be739e6c2cf.png align="center")
