Passing paths to shell script

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Passing paths to shell script Mon Mar 09, 2009 12:14 pm • by masonk
Hi, I am passing items to a shell script that wraps a ruby script. I noticed that the file names are truncated at the first space when they are passed. I need the script to operate on files that potentially have spaces in them. I'll give an example

~/Desktop/Total Deposit Report - 2333 Sat 03-07-2009 11-20p 4.pdf becomes ~/Desktop/Total

I noticed that each space delimited token is sent as another string in an array.

Here's what I had to do in Ruby to massage these paths:

path = ARGV.join(" "); path=path.chomp; path=path.chomp('\\'); path=path.delete"\""; path=path.delete"\'"

Is there a better way?
masonk
 
Posts: 3
Joined: Mon Mar 09, 2009 12:09 pm

Re: Passing paths to shell script Mon Mar 09, 2009 3:29 pm • by Mr_Noodle
Try quoting the file names. Use double-quotes if you still want variables inside to be expanded and single-quotes if you want it to be taken literally.

If the filename is being passed to you as a variable, then you want to use double-quotes like:
Code: Select all
"$1"
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion