Double dot at end of file

Hi,

I have an old script (date.sh) that is writing datas (currently just date) to a text file. It is a simple thing :) When I run this script now, the target file will be created, but the end of the filename will be two dots (proc_stat.txt..)

This is the script:
LOGFILE=/mnt/WORK/proc_stat.txt

date "+%Y.%m.%d %H:%M:%S" > "$LOGFILE"
Why are the two dots at the end of the file name?

Thanks!
 
My guess is that the scripts contain a bug and a command that is supposed to do something like

DEST=${OUTPATH}/..
mv ${OUTPATH}/${LOGFILE} ${DEST}

is actually doing something like

DEST=${OUTPATH}..
mv ${OUTPATH}/${LOGFILE} ${DEST}

(note the missing / in DEST)
 
My guess is that the scripts contain a bug and a command that is supposed to do something like

DEST=${OUTPATH}/..
mv ${OUTPATH}/${LOGFILE} ${DEST}

is actually doing something like

DEST=${OUTPATH}..
mv ${OUTPATH}/${LOGFILE} ${DEST}

(note the missing / in DEST)

This is my script:
LOGFILE=/mnt/WORK/proc_stat.txt
date "+%Y.%m.%d %H:%M:%S" > "$LOGFILE"
As you can see, it does not contain dots (except the date).
 
What if you set LOGFILE to something like /tmp/proc_stat.txt? What's /mnt/WORK anyway? It's some filesystem, but what? Maybe the postfixed dots are something that got added at the filesystem layer, the script certainly doesn't create any.

Code:
dice@chibacity:/tmp/forum_test % cat date.sh
#!/bin/sh

LOGFILE=proc_stat.txt
date "+%Y.%m.%d %H:%M:%S" > "$LOGFILE"
dice@chibacity:/tmp/forum_test % sh date.sh
dice@chibacity:/tmp/forum_test % ls -al
total 8
drwxr-xr-x  2 dice wheel 128 Mar 18 19:47 .
drwxrwxrwt  9 root wheel 448 Mar 18 19:47 ..
-rw-r--r--  1 dice wheel  72 Mar 18 19:46 date.sh
-rw-r--r--  1 dice wheel  20 Mar 18 19:47 proc_stat.txt
dice@chibacity:/tmp/forum_test % cat proc_stat.txt
2024.03.18 19:47:51
dice@chibacity:/tmp/forum_test %
 
you can also check for non-printing characters in your script using cat -e filename EOL will end with dollar '$'
 
What if you set LOGFILE to something like /tmp/proc_stat.txt? What's /mnt/WORK anyway? It's some filesystem, but what? Maybe the postfixed dots are something that got added at the filesystem layer, the script certainly doesn't create any.

Code:
dice@chibacity:/tmp/forum_test % cat date.sh
#!/bin/sh

LOGFILE=proc_stat.txt
date "+%Y.%m.%d %H:%M:%S" > "$LOGFILE"
dice@chibacity:/tmp/forum_test % sh date.sh
dice@chibacity:/tmp/forum_test % ls -al
total 8
drwxr-xr-x  2 dice wheel 128 Mar 18 19:47 .
drwxrwxrwt  9 root wheel 448 Mar 18 19:47 ..
-rw-r--r--  1 dice wheel  72 Mar 18 19:46 date.sh
-rw-r--r--  1 dice wheel  20 Mar 18 19:47 proc_stat.txt
dice@chibacity:/tmp/forum_test % cat proc_stat.txt
2024.03.18 19:47:51
dice@chibacity:/tmp/forum_test %

I have tried it. The logifle new location is /tmp, but the situation is unchanged.

Here are my file systems:
/dev/ufsid/65f2b302b0ba2f75 on / (ufs, local, soft-updates)
devfs on /dev (devfs)
procfs on /proc (procfs, local)
WORK on /mnt/WORK (zfs, NFS exported, local, nfsv4acls)

Thanks
 
Edit: sorry, ignore this. The next comment is right.

Copying add adding shebang line at the top works as expected on my machine. Did you really copy all of the script? How are you invoking the script?

Code:
#!/bin/sh
LOGFILE=./date.txt

date "+%Y.%m.%d %H:%M:%S" > "$LOGFILE"
 
Well, this certainly appends two CR characters. But they normally shouldn't display as dots ....
Code:
$ cat -e test.sh
TEST=/tmp/test.txt^M$
echo "hello" > "$TEST"^M$
$ sh test.sh
$ ls /tmp/test.txt*
/tmp/test.txt??
 
replace your carriage return (\r) with the following command

sed -i -e 's/\r//g' filename


Edit:
maybe it's display it as dots because of the encoding that he's using.
The output of locale will be helpful.
 
Back
Top