質問

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