سؤال

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

هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top