Skip to content
Advertisement

how to extract a substring in bash

I have the following string in bash with length > 4

JavaScript

and I want to extract into str2 the 5 first charachter of str. So

JavaScript

How to do it with bash?

Advertisement

Answer

Do use the expression

JavaScript

So in this case:

JavaScript

See other usages:

JavaScript

Taken from:
wooledge.org – How can I use parameter expansion? How can I get substrings? How can I get a file without its extension, or get just a file’s extension?
Shell Command Language – 2.6.2 Parameter Expansion

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement