Search code examples
shellecho

Creating a file with a single space and no newline


For testing purposes I am trying to create a file that only contains a single space character. However it seems most methods I use add a new line at the end. I've tried using vi and nano for editing.

Also tried echo " " > file but nothing so far


Solution

  • This will do it:

    echo -n " " > file
    

    The -n option suppresses the (default) newline.

    If your system's implementation of echo does not recognize the -n option, then another alternative is:

    printf " " > file