2012-05-24 4 views
2

Я только что нашел этот фрагмент в руководстве Баша:Что пустая строка в Баше

A variable may be assigned to by a statement of the form 

    name=[value] 

If value is not given, the variable is assigned the null string. 

Что именно подразумевается под null string? Является, например,

local empty 

эквивалентно

local empty="" 

?

+0

Да. Они такие же. – tuxuday

ответ

5

«Пустая строка» - это нулевая длина. В вашем примере оба одинаковы.

Простой тест:

#!/bin/bash 
go(){ 
    local empty 
    local empty2="" 
    [[ -z $empty ]] && echo "empty is null" 
    [[ -z $empty2 ]] && echo "empty2 is null" 
    [[ $empty == $empty2 ]] && echo "They are the same" 
} 

go 

печатает:

empty is null 
empty2 is null 
They are the same