1

I'm trying to build a dynamic command to execute in an .sh file, however, when I do it, it seems that somehow it adds \r characters so command is not correctly executed.

Notice that I'm running this over windows, using bash.exe. A sample of code:

My command.cmd file:

bash --login -x command.sh Parameter1

My .sh file:

#!/bash
#export PATH=.
cmd="ssh-agent bash -c 'ssh-add /cygdrive/C/1ドル/id_rsa & lftp -u myUser, -e \"mirror --verbose / /cygdrive/C1ドル/Output; bye\" sftp://domain.com -p 22'"
eval "$cmd"

If I run the command statically, it works perfectly:

ssh-agent bash -c 'ssh-add /cygdrive/C/1ドル/id_rsa & lftp -u myUser, -e \"mirror --verbose / /cygdrive/C1ドル/Output; bye\" sftp://domain.com -p 22'

But if I run it as is on the .sh file, it outputs the following:

C:\MyFolder\bin>command.cmd
C:\MyFolder\bin>bash --login -x command.sh Parameter1
+ cmd='ssh-agent bash -c '\''ssh-add /cygdrive/C/Parameter1/id_rsa & lftp -
u myUser, -e "mirror --verbose / /cygdrive/C/Parameter1/Output; bye" sft
'://sftp.domain.com -p 22'\''
+ eval 'ssh-agent bash -c '\''ssh-add /cygdrive/C/Parameter1/id_rsa & lftp
-u myUser, -e "mirror --verbose / /cygdrive/C/Parameter1/Output; bye" sf
'p://sftp.domain.com -p 22'\''
++ ssh-agent bash -c 'ssh-add /cygdrive/C/Parameter1/id_rsa & lftp -u myUser, -e "mirror --verbose / /cygdrive/Parameter1/Output; bye" sftp://sft
'.domain.com -p 22
Identity added: /cygdrive/id_rsa (rsa w/o comment)
'] `/' [Bad port '22.]

My guess is since this is running on windows something is not well formed in the dynamic command variable so the command does not run well. If instead of eval I perform echo, the output is:

C:\MyFolder\bin>command.cmd
C:\MyFolder\bin>bash --login -i command.sh Parameter1
ssh-agent bash -c 'ssh-add /cygdrive/C/Parameter1/id_rsa & lftp -u myUser, -e "mirror --verbose / /cygdrive/C/Parameter1/Output; bye" sftp://sftp.domain.com -p 22'

Which seems perfect.

What am I not doing right here?

Thank you.

asked Dec 12, 2014 at 19:48
1
  • Try trimming your input (remove leading/trailing whitespace) Commented Dec 12, 2014 at 20:38

1 Answer 1

1

Nevermind, found out that it was Windows adding invalid characters. With Notepad++, saving as Unix/Linux worked like a charm.

answered Dec 16, 2014 at 21:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.