K
K
kvaks2022-03-02 15:32:48
bash
kvaks, 2022-03-02 15:32:48

How to split a line in bash?

Tell me how to get 2 variables from a string.
With the name of the project and the rest of the string from https://github.com/USERNAME/REPOSITORIES
get:

url = https://github.com/USERNAME/
repa = REPOSITORIES

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2022-03-02
@kvaks

#!/bin/bash
str="/usr/local/bin/blabla"
str1=${str%/*}
echo "[$str1]"
str2=${str##*/}
echo "[$str2]"

Is the principle clear? Adapt to you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question