15
votes

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?

3
I gave you a +1 because this is the first time I heard of fish.Burhan Khalid
;-) it's a really nice unix shell - you should give it a tryOlivier Refalo
in fish 3 :>file works nice.kyb

3 Answers

18
votes

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

true > file
1
votes

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.

0
votes

There is, and always was the magic method called touch which set change time to actual or create non-existent file. For compatiblity I suggest you to use this way in all scripts that you write (even if you write bash code).