Jason Michael
Jason Michael

Reputation: 569

how to use shellescape for a path with spaces in it

essentially, I have code like this (running on CentOS 6.5, ruby 2.3):

foo = "/opt/provisioning/workspace/jobs/This Has Spaces/files/thisfile.xml"
read_file_and_do_something_interesting(foo)

where we have:

def read_file_and_do_something_interesting(file_path)
  data = File.read(file_path)

which leads to error:

/opt/provision/jobs/lib/aws_tools.rb:498:in `read': No such file or directory @ rb_sysopen - /opt/provisioning/workspace/jobs/This Has Spaces/files/thisfile.xml (Errno::ENOENT)

So, I tried to use shellescape, like this:

read_file_and_do_something_interesting(foo.shellescape)

and still I get error:

/opt/provision/jobs/lib/aws_tools.rb:498:in `read': No such file or directory @ rb_sysopen - /opt/provisioning/workspace/jobs/This\ Has\ Spaces/files/thisfile.xml (Errno::ENOENT)

So, simply, how do you use this thing?

Upvotes: 0

Views: 166

Answers (1)

rrFeng
rrFeng

Reputation: 191

I think this file /opt/provisioning/workspace/jobs/This Has Spaces/files/thisfile.xml really not exists.

Can you run ls "/opt/provisioning/workspace/jobs/This Has Spaces/files/thisfile.xml"?

Upvotes: 2

Related Questions