如何检查MyVar是否仅包含带有BASH的if语句的数字.数字我指的是0-9.
即:
if [[ $MyVar does contain digits ]] <-- How can I check if MyVar is just contains numbers then do some maths with $MyVar else do a different thing fi
这里是:
#!/bin/bash if [[ $1 =~ ^[0-9]+$]] then echo "ok" else echo "no" fi
如果第一个参数只包含数字,则打印确定,否则不打印.你可以用:./ yourFileName.sh inputValue来调用它