“Tes Bash Substring” Kode Jawaban

Tes Bash Substring

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
Wide-eyed Wren

Memeriksa apakah ada substring dalam bash string

string='Haystack';

if [[ $string =~ "Needle" ]]
then
   echo "It's there!"
fi
Clumsy Coyote

Tes Bash Substring

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'

if grep -q "$SUB" <<< "$STR"; then
  echo "It's there"
fi
Wide-eyed Wren

Tes Bash Substring

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'

if [[ "$STR" =~ .*"$SUB".* ]]; then
  echo "It's there."
fi
Wide-eyed Wren

Tes Bash Substring

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'

case $STR in

  *"$SUB"*)
    echo -n "It's there."
    ;;
esac
Wide-eyed Wren

Jawaban yang mirip dengan “Tes Bash Substring”

Pertanyaan yang mirip dengan “Tes Bash Substring”

Lebih banyak jawaban terkait untuk “Tes Bash Substring” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya