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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.