Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to empty a file in fish?

Tags:

fish

In bash shell scripting, I would typically run :> file to empty a file.

Now using fish, things are slightly different and the above command doesn't work.

What is fish equivalent?

like image 323
Olivier Refalo Avatar asked Oct 30 '13 02:10

Olivier Refalo


2 Answers

Although it's not as short as :, true is a command that will work everywhere and produces no output:

true > file
like image 172
nandhp Avatar answered Jan 03 '23 01:01

nandhp


Probably the easiest way that will be work in both Fish and Bash is to do echo "" > file

EDIT: Commenter was absolutely right echo "" > file produces a file with a newline, the correct command I was thinking of to create an empty file is cat /dev/null > file.

like image 26
Paul Hamilton Avatar answered Jan 03 '23 00:01

Paul Hamilton