How to test if a variable is a number or string in Linux bash?

You can use regex to identify if a variable is a number or string in Linux bash.

Example:

Declare some variables with numbers and strings:

Create a function to test if a variable is a number or string:

Test if a variable is number or string in Linux bash:

Leave a Reply