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.

  • 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)'? May 2, 2014 at 13:23
  • @0xC0000022L Output is LANG=en_US.UTF-8. May 2, 2014 at 13:32
  • sorry for being unclear. I meant the output on both ends. May 2, 2014 at 13:37
  • Sorry for missing that... Unfortunately this command doesn't output anything on Windoze :/ May 2, 2014 at 13:44
  • 1
    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 May 2, 2014 at 14:34

2 Answers 2


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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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