replacing empty values in bash
Hi,
I'm executing the below bash script, but when the m variable doesn't get any value it becomes empty. I don't want that. Code:
for i in "$@" Code:
<string></string> Code:
<string>0</string> |
Code:
m=0; |
I think that this don't work after the first iteration.
For example, I get the value 9 in the first iteration , and in the 2nd iteration it doesn't exist a value. In that case I'll get Code:
<string>9</string> I think that the solution is to put an if clause, but the problem is that I don't know how can I check if the variable m has content or not. |
the solution is:
Code:
if [ "$m tr -d ' '" == "" ] |
Gees ... no need to reinvent the wheel. How about we just use bash builtins:
Code:
[[ $m ]] || m=0 |
Quote:
Code:
if [ "$(echo $m | tr -d ' ')" == "" ] Quote:
Code:
${m:=0} |
Quote:
|
All times are GMT -5. The time now is 04:22 AM. |