Syntax error checking whether account number is numeric

前端 未结 2 1228
挽巷
挽巷 2021-01-29 13:17
if [[ ${account_nr} =~ ^[0-9]+$ &&  ${from_account_nr} =~ ^[0-9]+$ ]]

This is intended to check whether the account number is numeric or not. I

2条回答
  •  佛祖请我去吃肉
    2021-01-29 13:49

    This line is correct with advanced shells like Bash, Zsh or Ksh.

    if [[ ${account_nr} =~ ^[0-9]+$ &&  ${from_account_nr} =~ ^[0-9]+$ ]]
    

    It won't work with POSIX shells but -still- it won't show syntax error. Instead it would show that the command [[ was not found. Other causes may be related to the if statement itself but you have to show us what message was exactly shown e.g. bash: syntax error near unexpected token `fi'

提交回复
热议问题