I have a variable setup like this:

SSH_EXEC="ssh -X -o ControlPath=~/.ssh/master-$$ -o ControlPersist=60"

The parameter in question is the -X, because if I then call this command within my local script

$SSH_EXEC user@server "./server_script.sh $aFile"

which in a nutshell does the following:

if [ -e /path/"$1".name ] || [ -e /path/"$1" ]
   do something
   echo "/path/"$1".name"

Everything works! But if I replace -X with -t, my server_script fails to the else on the test. I'd prefer not use x11, but I'm not sure what the difference is that is causing it to fail in one instance, and pass in the other.


So I just did more troubleshooting and decided to echo the value of /path/$1.name on the server and it is garbled junk. If my $aFile name happened to be hello.name the result of the echo shows .nameello and also rids the beginning of the path when I use -t in place of -X.

What could be causing the corruption of my variables?

  • You aren't using X11. In one case you enable X11 forwarding, in the other you force a pseudo-tty to be created. Also, your code "in a nutshell" doesn't contain enough (not even the echo) to tell what the problem might be.
    – Hasturkun
    Jun 13, 2013 at 15:08
  • @Hasturkun I've modified my above example a little more. What I have "in a nutshell" is where my code fails. It's right at the beginning of a long server script. Jun 13, 2013 at 15:12
  • It's sort of a silly suggestion, but what happens if you pipe the output from your ssh command through xxd or similar?
    – Hasturkun
    Jun 13, 2013 at 15:17
  • @Hasturkun not a silly question! I don't know what xxd is, could you elaborate? Jun 13, 2013 at 15:19
  • Hex dump. I'm guessing there are control characters in your output, eg. a ^H (backspace) would delete the characters before it in shell output. Would be visible in a hex dump. In this case, my psychic powers tell me it's a ^M (Carriage return) at the end of $aFile
    – Hasturkun
    Jun 13, 2013 at 15:21

1 Answer 1


The variable $aFile probably has a trailing Carriage Return character, causing the terminal to return to the start of the line when encountered.

As an example, the following:

echo "/path/"hello^M".name"



This sort of thing might happen due to a shell script with DOS line endings, causing a line like

aFile = "hello"

to be interpreted as

aFile = "hello"^M

If that's the case, you should be able to convert your script to use Unix line endings using the dos2unix utility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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