Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
chaosite
on May 23, 2019
|
parent
|
context
|
favorite
| on:
The Art of Command Line (2015)
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`.
leviathan
on May 23, 2019
|
next
[–]
I've always done it as: `> file`
hultner
on May 23, 2019
|
parent
|
next
[–]
That's actually very nice, I never thought about that one.
hwj
on May 23, 2019
|
parent
|
prev
|
next
[–]
Unfortunately, this doesn't work in fish:
> fish: Expected a command, but instead found a redirection
danaur
on May 23, 2019
|
root
|
parent
|
next
[–]
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
on May 24, 2019
|
root
|
parent
|
next
[–]
Funny how the same sentence applies to bash wrt POSIX shell in other contexts
naniwaduni
on May 23, 2019
|
prev
|
next
[–]
Or after thinking about it for a moment, true > file. Or by its shorter name, :> file.
hultner
on May 23, 2019
|
prev
|
next
[–]
`printf > file`, but there's endless ways of achieving the same thing (and that's part of the beauty).
luckman212
on May 23, 2019
|
prev
[–]
Trick: You can use just
>file
Consider applying for YC's Spring batch! Applications are open till Feb 11.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: