Results 1 to 3 of 3
Thread: Simple string related question
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
10-17-2012 #1
- Join Date
- Oct 2012
- Posts
- 10
Simple string related question
I'm trying to write a bash script, and wondering what the best way of manipulation a returned string is.
A variable $scriptString that stores the stdout of a command i run, can end up containing either "Build OK" or "Build failed. Creator: somename"
I want to check if $scriptString contains "Build failed" and then grab "somename" and store it in a new variable. I'm not sure how to get at it though. This is where I'm at now:
if [[ "$scriptString == *Build failed*"]]; then
fi
What should I do in the if statement to extract "somename" ?
Thanks!
-
10-17-2012 #2
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 480
something like this might work:
if [[ "$scriptString == *Build failed*"]]; then
echo $scriptString | cut -d: -f2
fithe sun is new every day (heraclitus)
-
10-19-2012 #3
- Join Date
- Oct 2012
- Posts
- 10
Thanks alot! Just what I was looking for.