0

I am trying to run a bash script in Visual Studio Code using the bash shell. What I'am trying to do is to read a .csv file within a directory "OneDrive - research institution project/files" using sed 1d $p_path$csv_name | while IFS=, read -r gcm xml_nm xml_m co2con batchy.

Besides the scripting for reading the .csv file, which works because it has been already used, everytime I run it for my folder I get problems due to the blank spaces in the folder path.

I already tried to use \, and both double and single quotes ( p_path = "OneDrive\ -\ research\ institution\ project/files" or p_path = 'OneDrive - research institution project'/files or p_path = "OneDrive - research institution project/files"

but nothing worked so far, returning always errors like: sed: unknown option -- \ Assuming that I cannot change the name of the directory, is there a way to solve the problem?

  • "_I already tried to use \, and both double and single quotes but_" show _exactly_ what you tried. There is a non-zero chance you just did it wrong and if you don't show what you tried, nobody will know whether that's the case. – starball Apr 27 '23 at 07:52

1 Answers1

0

You might not have to escape the spaces, if the variables are used correctly (see shellcheck.net for confirmation):

sed 1d "${p_path}${csv_name}"

Then there is the while, which seems to be missing a do/done.

If you want the input of while loop to come from output of command, that would be:

sed 1d "${p_path}${csv_name}" | while IFS=, read -r gcm; do xml_nm xml_m co2con batchy; done
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250