2007/06/03

create or set a file to null length

is this form a valid form to create or to set a file to length = 0???


> $FILE


# ---
Joachim Schmitz
Provided the variable $FILE isn't empty: yes
Bye, Jojo

# ---
If $FILE might contain spaces or shell metacharacters it should be
enclosed in double quotes.

Mans Rullgard

Only with bash or with POSIX shells when they are interactive.
But it's always better to quote variables anyway.

--
Stéphane


# ---
Stephane CHAZELAS

Not with every shell (not with bash where you need to quote
$FILE, not with shells like zsh that have a default command when
you don't provide any).


: > "$FILE"


is more correct and more portable and more legible.

":" can be replaced with any command that doesn't output
anything like true, eval... but ":" is the best bet as it's in
every shell and it's builtin in everyshell.

--
Stéphane

No comments: