[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash string RE pattern matching
From: |
Lee |
Subject: |
bash string RE pattern matching |
Date: |
Wed, 26 Jul 2023 19:13:38 -0400 |
Why doesn't =~ match strings inside of double quotes?
$ bash bashre
os = "Linux" re = "^Linux"
"$os" =~ ${re} is true
"$os" =~ "${re}" is False
"$os" =~ ^Linux is true
"$os" =~ "^Linux" is False
$ cat bashre
#!/bin/bash
# what's going on???
os=`/bin/uname`
re="^Linux"
echo "os = \"$os\" re = \"$re\""
echo -n "\"\$os\" =~ \${re} is "
if [[ "$os" =~ ${re} ]]; then
echo "true"
else
echo "False"
fi
echo -n "\"\$os\" =~ \"\${re}\" is "
if [[ "$os" =~ "${re}" ]]; then
echo "true"
else
echo "False"
fi
echo -n "\"\$os\" =~ ^Linux is "
if [[ "$os" =~ ^Linux ]]; then
echo "true"
else
echo "false"
fi
echo -n "\"\$os\" =~ \"^Linux\" is "
if [[ "$os" =~ "^Linux" ]]; then
echo "true"
else
echo "False"
fi
Thanks
Lee
- bash string RE pattern matching,
Lee <=