Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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


    What should I do in the if statement to extract "somename" ?


  2. #2
    Linux User
    Join Date
    Jan 2007
    something like this might work:

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

  3. #3
    Thanks alot! Just what I was looking for.

  4. $spacer_open

Posting Permissions

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