Re: OT: bashfråga

Michael Kjörling <[email protected]>
Newsgroups gmane.linux.debian.user.swedish
Message-ID <[email protected]>
On 30 Mar 2015 15:59 +0200, from [email protected]:
> Jag behöver en fil som innehåller en datumsträng utan LF i slutet.
> Skulle naturligtvis kunna skriva ett C-program som ger mig exakt det
> men jag skulle vilja göra det i ett bash-script.
> 
> Nedanstående fungerar men det känns väldigt yxigt, speciellt
> sed-kommandot. Någon som har ett bättre förslag?
> 
> date +"%Y%m%d_%H%M%S" > tmp
> sed s/\
> // tmp > NEWDATE 2> /dev/null

$ echo -n "$(date +'%Y%m%d_%H%M%S')" > tmp
$ hexdump -C tmp
00000000  32 30 31 35 30 33 33 30  5f 31 36 31 39 30 37     |20150330_161907|
0000000f
$

kanske kan vara något?

Alternativt använd "printf" istället för "echo -n":

$ printf "%s" "$(date +'%Y%m%d_%H%M%S')" > tmp

för samma resultat.

-- 
Michael Kjörling • https://michael.kjorling.se • [email protected]
OpenPGP B501AC6429EF4514 https://michael.kjorling.se/public-keys/pgp
                 “People who think they know everything really annoy
                 those of us who know we don’t.” (Bjarne Stroustrup)


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: https://lists.debian.org/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.