I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed command. After substitution I echo the path just for check and it is correct. Then comes the second sed command which has to deal with the file for which I wrote the absolute path. Well it won't work... It looks like In the second command $drill_file isn't expanding. The weirdest thing is that it expands just fine outside the script... WOOT!?#!/bin/bashecho Give relative or absolute path to the \drill.TXT\ file:read drill_file_tempdrill_file=$(echo $drill_file_temp | sed -r 's/\s/\\ /g')echo $drill_filesed 's/\(^X[[:digit:]]*\)[[:digit:]]\(Y[[:digit:]]*\)[[:digit:]]/\1\2/' $drill_fileecho Conversion finished.
sed won't expand my BASH variable in script
bash;sed;quoting;variable
You put quoting chars into a string. The problem is that quoting chars are not parsed after parameter expansion. In order to get the desired effect you would needeval sed ... $drill_fileYou can use set -x to see how the shell sees the command line:> text=a\\\ \\\ \\\ b> echo $texta\ \ \ b> set -x> : $text+ : 'a\' '\' '\' bI.e. the shell does not see one argument but four.As aleady said by the others: You must quote $drill_file / $drill_file_temp: $drill_file