0

This question already has an answer here:

I am running a very simple bash script on Macosx Yosemite

#!/bin/bash
makefilePath=$(echo $(pwd)/make.sh | sed 's/ /\\ /')
echo $makefilePath
source "$makefilePath"

The first three lines work as expected, but the fourth line creates a returns an error No such file or directory, even though if I run the command from makefile directly in the shell by copy pasting it, it works fine.

I don't know what the problem is. Please help.

marked as duplicate by Gilles bash Sep 7 '16 at 22:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You didn't write what it is your actual PWD, but I assume it contain a space, so the sed command will mangle the filename, and it will no more represent the original file.

The mangled filename is interpreted literally by shell expansion (and with double quotes). Note also '\\' will not do what you are probably want.

Not the answer you're looking for? Browse other questions tagged or ask your own question.