Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
chaosite
· 7y ago · 0 comments
Well, `echo > file` won't empty the file, it will have a newline in it. At the very least you'll need `echo -n > file`.
Comments
[–]
leviathan
7y ago
I've always done it as: `> file`
[–]
hultner
7y ago
That's actually very nice, I never thought about that one.
[–]
hwj
7y ago
Unfortunately, this doesn't work in fish:
> fish: Expected a command, but instead found a redirection
[–]
danaur
7y ago
Right but I don't think anyone is really concerned if it runs in fish. Fish is non standard and doesn't try to adhere to bash. If we want to write fish shell scripts we can do that elsewhere
[–]
jgtrosh
7y ago
Funny how the same sentence applies to bash wrt POSIX shell in other contexts
[–]
naniwaduni
7y ago
Or after thinking about it for a moment, true > file. Or by its shorter name, :> file.
[–]
hultner
7y ago
`printf > file`, but there's endless ways of achieving the same thing (and that's part of the beauty).
[–]
luckman212
7y ago
Trick: You can use just
>file