push () { date "+%F/push/$1" >> /tmp/pushlog.txt; }
This defines a shell function that appends the string to the /tmp/pushlog.txt
file.
The format string used with date
incorporates the first command line argument of the shell function.
bash-4.4$ push 123
bash-4.4$ push "hello world"
bash-4.4$ push "%s"
bash-4.4$
bash-4.4$ cat /tmp/pushlog.txt
2017-08-29/push/123
2017-08-29/push/hello world
2017-08-29/push/1504041277
If you're planning to use push
to push strings that may be interpreted by date
(like the last example), and if that's not what you want, then use this instead:
push () { printf '%s/push/%s\n' "$(date '+%F')" "$1" >> /tmp/pushlog.txt; }
The reason you get an unwanted newline in your file is that date
outputs a newline at the end of its output. This newline is removed when using date
in $(...)
as I did in the second implementation of my shell function above.