1

In a bash script I want to do that but it doesn't work

config.txt :

newdir="build/src"

script.sh :

#!/bin/bash


source config.txt
cd $newdir

: No file or folder of this type

I have this with bash +x script.sh

+ source config.txt
++ newdir=$'build/src\r'
+ cd $'build/src\r'
: Aucun fichier de ce type
11
  • 2
    bash is Case-Sensitive.... and source is a keyword in bash you should use another variable name, e.g. newdir="build/src" then source config.txt and cd "$newdir". Commented Mar 8, 2019 at 9:02
  • it doesn't work too with an other name Commented Mar 8, 2019 at 9:44
  • 1
    What you call the variable make no difference at all -- you just want a name that doesn't conflict with a reserved word. Do this run your script.sh as bash -x script.sh and post the output to tell us where it is failing. Just add it to your question (with each line indented by 4-spaces so it formats correctly) and that will tell us exactly what is going on. You still have source config.txt unchanged - right? And the build/src directory is in the current working directory when you run the script right? The config.txt file is also in that same directory too? Commented Mar 8, 2019 at 9:50
  • 2
    \r by the end of your file path is part of a Window's linefeed, you will want to remove it (retype the path by hand). The error appear as an empty filename because \r is the carriage return char which makes the cursor go back to the start of the line, where : No file or folder of this type will overwrite the file name Commented Mar 8, 2019 at 10:13
  • 1
    With Notepad++ use Edit -> EOL Conversion -> Unix (LF) in the menus ; you will probably see that the Windows (CR LF) menu item is grayed since that's your current linefeeds style (or in the status bar at the bottom of the window you can see "Windows (CR LF)" as the third item from the right) Commented Mar 8, 2019 at 10:18

1 Answer 1

3

The problem came from invsible \r (carriage return) generated by windows at the end of lines. I change the EOL Conversion to Unix (LF)!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.