Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 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 "./ $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/$ on the server and it is garbled junk. If my $aFile name happened to be 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?

share|improve this question

migrated from Jun 13 '13 at 16:35

This question came from our site for professional and enthusiast programmers.

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 '13 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. – free_mind Jun 13 '13 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 '13 at 15:17
@Hasturkun not a silly question! I don't know what xxd is, could you elaborate? – free_mind Jun 13 '13 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 '13 at 15:21
up vote 2 down vote accepted

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.

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.