I have here the code:
#/bin/sh
cd ~/Desktop/tmp
date "+%m%d%y_%H%M%S_" | xargs -0 mkdir;
This will create a directory with the current date.
The problem here is that the date command will return a date with a newline character at the end.
After mkdir, the folder created will include a newline.
Anybody know how to go about this? I need a folder name without the newline character.
Thanks.
why do you need to pass it to xargs? Don't do the unnecessary
mkdir $(date "+%m%d%y_%H%M%S_")
The reason that the newline was included, is that you used the -0 option, which makes xargs use null byte (ASCII 000) as a word boundary. Newlines are then included as part of the words. Dropping -0 makes xargs use whitespace (including newline) as boundary, thus chopping it off.
However, use ghostdog74's solution, it's simpler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With