Fish-shell: How can i test a string in another string ?

Created on 19 Jan 2013  ·  4Comments  ·  Source: fish-shell/fish-shell

say i want to if "Darwin or Linux" in echo (uname -a) , i tried contains , it doesn't work , because contains test if a word is present in a list .

is there a easy way to do this ?

thanks !

question

Most helpful comment

Another way would be

switch (uname -a)
    case "*Darwin*"
        echo darwin stuff
    case "*Linux*"
        echo linux stuf
end

But I guess this question is answered, so I'll close it.

All 4 comments

switch (uname -a | cut -d ' ' -f 1)
  case 'Darwin'
    echo 'do stuff'
  case 'Linux'
    echo 'do other stuff'
end

You could also use grep, especially if you wanted to do the same action for any of these.

if uname -a | grep 'Darwin\|Linux' >/dev/null
  echo 'do stuff'
end

thanks terlar .

hi terlar , i think your grep version is better , because i can detect if it is ubuntu , then i can define some function only work in Ubuntu . it's more specific .

thanks again .

Another way would be

switch (uname -a)
    case "*Darwin*"
        echo darwin stuff
    case "*Linux*"
        echo linux stuf
end

But I guess this question is answered, so I'll close it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewhowdencom picture andrewhowdencom  ·  3Comments

badp picture badp  ·  3Comments

krader1961 picture krader1961  ·  3Comments

euclio picture euclio  ·  3Comments

olivergondza picture olivergondza  ·  3Comments