Search code examples
bashvariablesgithubpathcd

Bash: error with cd and path variables


Here is the code in question:

path_prefix='opt/copyright_service/gitHub'
while read line
do
    user=$line
    echo $user
    while read line
    do
        repoName=$line

        path="/$path_prefix/$user"

        echo $path

        cd $path
    done < $2
done < $1

The output is:

username
/opt/copyright_service/gitHub/username
: No such file or directoryopyright_service/gitHub/username

Why is it not recognizing the full path in the cd command? Before I added in the user feature I had it reading a repository name from a file, and it did that without a problem, but now that I have it doing both, it doesn't work.

The content of the file it is reading is "username"

I have tried many ways of concatenating $path, by specifying path prefix as cd is called, by concatenating $path_prefix and $user in the cd command(cd /$path_prefix/$user)

Any ideas?


Solution

  • Big guess: Your script is not in UNIX format. Try using dos2unix with it, or use an editor that can convert it well. Using sed -i -e 's|\r||' your_script.sh may work as well.

    If not, it's probably the input files that aren't.