Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date.

DATE=$(date +"%Y%m%d")
php -q script.php >> $FILE 2>&1

When I run this script on my local machine (Windows 7, Aptana IDE), the PHP script works fine and the logfile has the expected filename, e.g. 20140502.log.

But when I push that script via SFTP to my remote machine and execute that script, the filename looks like this:


What might be the problem? Is this an enconding error (e.g. encoding for SFTP uploads is ANSII, where UTF-8 is expected)? Or do I have to change anything in the script itself?

Information about system/shell:

[foo@bar path]$ sh --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

Funny fact: If that script is called by a cronjob, the question marks don't occur. Only if I manually run the script.

share|improve this question
Usually the ? indicates that a character cannot be displayed. Certainly sounds like an encoding difference. Can you give us the output of env|grep -E '(LC|LANG)'? – 0xC0000022L May 2 '14 at 13:23
@0xC0000022L Output is LANG=en_US.UTF-8. – Gottlieb Notschnabel May 2 '14 at 13:32
sorry for being unclear. I meant the output on both ends. – 0xC0000022L May 2 '14 at 13:37
Sorry for missing that... Unfortunately this command doesn't output anything on Windoze :/ – Gottlieb Notschnabel May 2 '14 at 13:44
Are you aware that this sequence of redirections (2>&1 >> $FILE) sends stderr to the terminal and stdout to the file? If you want stderr to go to the file as well, you need >> $FILE 2>&1 – glenn jackman May 2 '14 at 14:34
up vote 9 down vote accepted

You probably have some non-printable characters on end of lines (eg. CRLF from Windows), run:

cat -A scriptname

on remote machine, it'll show you all characters in your script. Then, you can convert to unix-like format running

dos2unix scriptname
share|improve this answer
Thanks, that was helpful! – Gottlieb Notschnabel May 2 '14 at 13:33

Found Notepad ++ to be very useful for correcting this after attempting the answer

cat -A scriptname>

dos2unix scriptname

as this still presented errors when trying to convert.

Through Notepad ++ there's the option in the edit menu/EOL Conversion/Unix/OSX Format.

Still very much a learner but this method solved my problem, however the previous solution assisted in finding where the problem was.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.