why does if [ ${var:0:2}='AA' ] always return true
Hi and happy new year !
can someone tell me why does if [ ${var:0:2}='AA' ] always return true, and tell me how to change if to test the first two characters in variable var ? Greetings, Ron |
Happy new year to you too.
That happens because you need to have spaces around the '='. It's also better (at least in this case) to have double quotes around ${var:0:2}. Without the double quotes you'll get an error if "var" happens to be emtpy. So, this works: Code:
#!/bin/bash |
All times are GMT -5. The time now is 01:19 PM. |