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 !
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.
Most helpful comment
Another way would be
But I guess this question is answered, so I'll close it.