Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I got a task to create a bash script to install Subversion scheduler on my freebsd machine, unfortunately it doesn't work as expected.

when I run

#bash -x ./installSubversion.sh

I always got this error messages

+ REPOPATH=$'/usr/ports/devel/subversion\r'
+ CHECKPATH=$'/usr/local/bin/svnserve\r'
>./installSubversion.sh: line 22: syntax error: unexpected end of file

here is the script installSubversion.sh

#!/usr/bin/env bash
###########
### Installing subversion(svn) on Freebsd
###########
REPOPATH="/usr/ports/devel/subversion"
CHECKPATH="/usr/local/bin/svnserve"
if [ ! -x "$CHECKPATH"  ] || [ "$1" = "-force" ] ;
then
        echo "Trying to install subversion from ports"
        if [ "$1" = "-force"  ];
        then
                /usr/sbin/pkg_delete -fx subversion-
                cd $REPOPATH
                /usr/bin/make -DBATCH reinstall clean
        else
                cd $REPOPATH
                /usr/bin/make -DBATCH install clean
        fi
else
        echo "subversion is Installed"
fi

What am I doing wrong?

share|improve this question
1  
Nothing to do with the issue, but it is not necessary to have both a semicolon (;) and a newline before the then part of an if statement. Have you deleted the inner if ... fi to try and get the same error message? –  Anthon Jan 18 at 8:09
    
@Anthon I think that is everything to do with it, fi\r does not end an if –  Jasen Jan 18 at 8:49
    
@Jasen AFIAK you can insert them and leave them out if the then is on the next line. Care to elaborate? –  Anthon Jan 18 at 8:52
    
@Jasen: Fair point. Some may consider it a bug that bash doesn't ignore \r at the end of a line, others consider it a feature. :) –  PM 2Ring Jan 19 at 7:02

1 Answer 1

up vote 3 down vote accepted

The error messages REPOPATH=$'/usr/ports/devel/subversion\r' indicate that your script has DOS-style line endings \r\n instead of Unix-style \n. That can be fixed with a simple sed command, or using the dos2unix command, which you may have already installed on your system.

Your text editor may have an option to select line ending style. If so, make sure you use Unix-style when editing scripts for use in *nix. And you can use such an editor to convert the line ending style of existing files, but that can be a bit tedious if you want to fix multiple files.

share|improve this answer
    
looks to me the good answer, along with no ; in if statement. –  Archemar Jan 18 at 10:15
    
Thanks THIS WORKS !!! –  Adhi Wirawan Jan 18 at 13:19

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.