There is no better way I know of. Bash knows only status codes (integers) and strings written to the stdout.
More Related Contents:
- How to check if a string contains a substring in Bash
- How to compare strings in Bash
- How to use sed/grep to extract text between two words?
- How to trim whitespace from a Bash variable?
- Getting “command not found” error while comparing two strings in Bash
- How do I use variables in single quoted strings?
- Return value in a Bash function
- How to get a variable value if variable name is stored as string?
- Extract substring in Bash
- In Bash, how can I check if a string begins with some value?
- How do I remove the file suffix and path portion from a path string in Bash?
- Get string after character [duplicate]
- Call functions with special prefix/suffix
- Test whether string is a valid integer
- How to test if string exists in file with Bash?
- Bash doesn’t parse quotes when converting a string to arguments
- Replacing some characters in a string with another character
- Bash: Split string into character array
- Multi-line string with extra space (preserved indentation)
- Extract part of a string using bash/cut/split
- How can I compare a string to multiple correct values in Bash?
- Difference between return and exit in Bash functions
- Shell script – remove first and last quote (“) from a variable
- Use character string as function argument
- How to echo “$x_$y” in Bash script?
- Convert specified column in a multi-line string into single comma-separated line
- bash : Bad Substitution
- Bash: manipulating with strings (percent sign)
- Test for empty string with X”” [duplicate]
- Split bash string by newline characters