Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何验证字符串是否为字母数字组合(包含字母和数字)#linux#Bash 猛击_Linux - Fatal编程技术网

如何验证字符串是否为字母数字组合(包含字母和数字)#linux#Bash 猛击

如何验证字符串是否为字母数字组合(包含字母和数字)#linux#Bash 猛击,linux,Linux,我试过这个: a="abc123" if ! [[ $a =~ [^a-zA-Z0-9] ]]; then echo " a is alphanumeric" else echo " a is not alphanumeric" 但是这个函数验证字符串是只有字母还是只有数字,不是两者都有,我不知道如何使它工作。我查了一下谷歌,但没发现什么 #!/bin/bash a="abc123" if ([[ $a =~ [a-

我试过这个:

a="abc123"
if ! [[ $a =~ [^a-zA-Z0-9] ]]; then
    echo " a is alphanumeric"
else 
    echo " a is not alphanumeric"
但是这个函数验证字符串是只有字母还是只有数字,不是两者都有,我不知道如何使它工作。我查了一下谷歌,但没发现什么

#!/bin/bash
a="abc123"
if ([[ $a =~ [a-zA-Z] ]] && [[ $a =~ [0-9] ]]); then
    echo " a is alphanumeric"
else 
    echo " a is not alphanumeric"
fi