Reputation: 1695
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.
Upvotes: 3
Views: 3290
Reputation: 1567
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.
Upvotes: 2
Reputation: 343057
why do you need to pass it to xargs
? Don't do the unnecessary
mkdir $(date "+%m%d%y_%H%M%S_")
Upvotes: 6