Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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" ]
then 
   do something
else
   error
   echo "/path/"$1".name"
   exit
fi  

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.

EDIT

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?

share|improve this question

migrated from stackoverflow.com 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. –  inquisitor 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? –  inquisitor 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
show 3 more comments

1 Answer

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"

outputs:

/.namehello

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
add comment

Your Answer

 
discard

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.