Find the answer to your Linux question:
Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By tpl
Hi! 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    10

    Simple string related question


    Hi!

    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!

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    477
    something like this might work:

    if [[ "$scriptString == *Build failed*"]]; then
    echo $scriptString | cut -d: -f2
    fi
    q-bertsuit likes this.
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    10
    Thanks alot! Just what I was looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •