If you want it to be like a script, the following Bash script should do what you need (plus indicate when the file already exists):
#!/bin/bash if [ -e $1 ]; then echo "File $1 already exists!" else echo >> $1 fi
If you do not need the message "already exists", you can use:
#!/bin/bash if [ ! -e $1 ]; then echo >> $1 fi
Change usage:
Save any version with a name that you like, say "create_file" (mine quotes, you donβt want them in the file name). Then, to make the executatble file, at the command prompt, run:
chmod u+x create_file
Put the file in a directory in your path , and then use it with:
create_file NAME_OF_NEW_FILE
$ 1 is a special shell variable that takes the first argument on the command line after the program name; those. $ 1 will receive NAME_OF_NEW_FILE in the above use case.
GreenMatt Jan 11 2018-11-11T00: 00Z
source share