[Solved-4 Solutions] Test-line 4-2- command not found
Error Description:
- When we try the following code:
- We get the following error:
Test-line 4-2- command not found
Solution 1:
- Just like any other simple command, [ ... ] or test requires spaces between its arguments.
- Or
- When in Bash, prefer using [[ ]] instead as it doesn't do word splitting and pathname expansion to its variables that quoting may not be necessary unless it's part of an expression.
- It also has some other features like unquoted condition grouping, pattern matching (extended pattern matching with extglob) and regex matching.
- The following example checks if arguments are valid. It allows a single argument or two.
- For pure arithmetic expressions, using (( )) to some may still be better, but they are still possible in [[ ]] with its arithmetic operators like -eq, -ne, -lt, -le, -gt, or -ge by placing the expression as a single string argument:
- That should be helpful if you would need to combine it with other features of [[ ]] as well.
Solution 2:
- It might be a good idea to use arithmetic expressions if you're dealing with numbers.
Solution 3:
- A simple one liner that works can be done using:
- This breaks down to:
- test the bash variable for size of parameters $# not equals 1 (our number of sub commands)
- if true then call usage() function and exit with status 1
- else call main() function
- Thinks to note:
- usage() can just be simple echo "$0: params"
- main can be one long script
Solution 4:
- If you're only interested in bailing if a particular argument is missing, Parameter Substitution is great: