Pregunta

I have a "my-variable-here" environment variable.

e.g.

my-variable-here=/var/log/test

I want to get the text between the equal sign and the 2nd slash. So in my example above, I want to get the text "/var".

how do I do it?

thanks very much

¿Fue útil?

Solución

you might want to use "cut" and slash as a delimiter

export my_variable_here=/var/log/test
part2=`echo $my_variable_here | cut -f2 -d"/"`
result="/$part2"
echo $result
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top