diff --git a/patches/patch.sh b/patches/patch.sh
index 775bd6d5d36208a5945f2c60a2b34e99d43ffe13..dafd2525f95c89d7c30e8b6836d144b161e04188 100755
--- a/patches/patch.sh
+++ b/patches/patch.sh
@@ -259,7 +259,7 @@ case "$action" in
     fi
 
     echo ""
-    if grep -q "D__PLUMED_MPI=1" $PLUMED_ROOT/src/config/compile_options.sh ; then
+    if grep -q "D__PLUMED_MPI=1" "$PLUMED_ROOT"/src/config/compile_options.sh ; then
       echo "PLUMED is compiled with MPI support so you can configure $engine with MPI" 
     else
       echo "PLUMED is compiled WITHOUT MPI support so you CANNOT configure $engine with MPI"
diff --git a/scripts/mklib.sh b/scripts/mklib.sh
index 742aa376583aaef6e1739aea274e69a9d5a032de..2612a488ab01d8a125ed8c7b4c497fb876a108a3 100755
--- a/scripts/mklib.sh
+++ b/scripts/mklib.sh
@@ -1,6 +1,6 @@
 #! /bin/bash
 
-source $PLUMED_ROOT/src/config/compile_options.sh
+source "$PLUMED_ROOT"/src/config/compile_options.sh
 
 if [ "$1" = --description ] ; then
   echo "compile a .cpp file into a shared library"
diff --git a/scripts/newcv.sh b/scripts/newcv.sh
index d0c99d0705a2348c3bcec345cb770ad20a3a13e3..b3b57373937bae656cfb8c99458f96712c0a27ba 100755
--- a/scripts/newcv.sh
+++ b/scripts/newcv.sh
@@ -17,5 +17,5 @@ directive=$1
 classname=$2
 
 sed "s/TEMPLATE/$directive/g
-     s/Template/$classname/g" $PLUMED_ROOT/src/colvar/Template.cpp > ${classname}.cpp
+     s/Template/$classname/g" "$PLUMED_ROOT"/src/colvar/Template.cpp > ${classname}.cpp
 
diff --git a/scripts/patch.sh b/scripts/patch.sh
index b3b00e052165540dee9fdc79f44c4991de405da8..d9bfe5d30bba0e44d3aa29e4ff709a3e6fb335d0 100755
--- a/scripts/patch.sh
+++ b/scripts/patch.sh
@@ -1,4 +1,4 @@
 #! /bin/bash
 
-${PLUMED_ROOT}/patches/patch.sh "$@"
+"${PLUMED_ROOT}"/patches/patch.sh "$@"
 
diff --git a/src/config/Makefile b/src/config/Makefile
index a4b9d0dbd535bc4948465824f455231b3d8018ff..fae0e2748e86050caf2649dfa39cc557dae3d777 100644
--- a/src/config/Makefile
+++ b/src/config/Makefile
@@ -51,7 +51,7 @@ Makefile.conf.xxd: ../../Makefile.conf
 # file to import compilation options inside a bash script
 compile_options.sh:
 	@echo Building compile_options.sh, a sourceable bash script with some compilation options
-	@echo "compile='"$(CXX) -c -I'$$PLUMED_ROOT'/src $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
+	@echo "compile='"$(CXX) -c -I'"$$PLUMED_ROOT"'/src $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
 	@echo "link='"$(LDSO) -o"'" >> $@
 	@echo "soext='"$(SOEXT)"'" >> $@
 
diff --git a/src/core/CLToolMain.cpp b/src/core/CLToolMain.cpp
index a77e2b1cc3e0df8c9a41c88ae57a173e915f2856..891920ea7422ce79468f55ef9860fe77ab0c6d8c 100644
--- a/src/core/CLToolMain.cpp
+++ b/src/core/CLToolMain.cpp
@@ -210,7 +210,7 @@ int CLToolMain::run(int argc, char **argv,FILE*in,FILE*out,Communicator& pc){
       fprintf(out,"  plumed %s\n", manual.c_str());
     }
     for(unsigned j=0;j<availableShell.size();++j){
-      string cmd="env PLUMED_ROOT="+root+" "+root+"/scripts/"+availableShell[j]+".sh --description";
+      string cmd="env PLUMED_ROOT=\""+root+"\" \""+root+"/scripts/"+availableShell[j]+".sh\" --description";
       FILE *fp=popen(cmd.c_str(),"r");
       string line,manual;
       while(Tools::getline(fp,line))manual+=line;
@@ -241,7 +241,7 @@ int CLToolMain::run(int argc, char **argv,FILE*in,FILE*out,Communicator& pc){
   if(find(availableShell.begin(),availableShell.end(),command)!=availableShell.end()){
     plumed_massert(in==stdin,"shell tools can only work on stdin");
     plumed_massert(out==stdout,"shell tools can only work on stdin");
-    string cmd="env PLUMED_ROOT="+root+" "+root+"/scripts/"+command+".sh";
+    string cmd="env PLUMED_ROOT=\""+root+"\" \""+root+"/scripts/"+command+".sh\"";
     for(int j=i+1;j<argc;j++) cmd+=string(" ")+argv[j];
     system(cmd.c_str());
     return 0;
diff --git a/src/lib/Makefile b/src/lib/Makefile
index eaf552227a366583760b1d6a2162ad2a77dfe73a..6ae35c704294f52c04d8d118889472fe3cb05454 100644
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -206,7 +206,7 @@ $(PLUMED_MAIN_STATIC): $(OBJ_MAIN) $(OBJ_KERNEL) $(OBJ_WRAPPER)
 	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS) $(DYNAMIC_LIBS)
 	
 $(PLUMED_MAIN_SHARED): $(OBJ_MAIN) $(PLUMED_SHARED_OBJ)
-	$(LD) $(LDFLAGS) $(OBJ_MAIN) $(realpath $(PLUMED_SHARED_OBJ)) -o $@ $(LIBS)
+	$(LD) $(LDFLAGS) $(OBJ_MAIN) "$(realpath $(PLUMED_SHARED_OBJ))" -o $@ $(LIBS)
 
 $(PLUMED_MAIN_RUNTIME): $(OBJ_MAIN) $(OBJ_DYNAMIC_WRAPPER)
 	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)