slashes in shell script

Hi all,
is it possible to write a shell script that incorporates a / in a filename e.g. my/name/is.pdf. I know that shell interprets a / as a directory path but unforunatley I have some files that have slashes in there filenames and I need to retain the slashes, but when I pass the filename as a variable to shell I know it’s going to give me a problem.

You can escape any character with a backslash "". This will stop the shell from interpreting that character with its special meaning. So before you pass the file name to the shell use applescript’s text item delimiters to put a backslash before any forward slashes.

that’s just what I needed,
Thanks very much


anyway it’s strongly recommended to avoid colons and slashes in file names

I am pretty sure that backslashes will not help here. It is the kernel that is interpreting the meaning of the slash characters, not the shell. And I am pretty sure that the kernel does not honor backslashes for escaping (in fact, backslashes can be used in filenames).

If you have a file with an HFS filename of “my/name/is.pdf”, its POSIX filename is “my:name:is.pdf”. If you use something like choose file or are making a droplet, you can use POSIX path of to get the proper POSIX path for the file. When working with shell scripts, one should always use POSIX path of and quoted form of to prepare pathname arguments.

Here is a little demonstration of the equivalence of POSIX-colon and HFS-slash:

set prefix to "demo-" -- must not have slash or colon
set |POSIX name| to prefix & "POSIX:file:with:colons.txt"
set |HFS name| to prefix & "HFS/file/with/slashes.txt"
set fldr to path to temporary items folder from local domain
set fldr_pp to POSIX path of fldr

-- Create a slash/colon file via the shell (POSIX filename)
do shell script "cd " & quoted form of fldr_pp & ";touch " & quoted form of |POSIX name|
-- Create a slash/colon file via Finder (HFS filename)
tell application "Finder" to set ff to make new file at folder fldr with properties {name:|HFS name|}

-- Get the filenames according to ls (POSIX filenames)
set ls to paragraphs of (do shell script "cd " & quoted form of fldr_pp & "; ls " & quoted form of prefix & "*")
-- Get the filenames according to Finder (HFS filenames)
tell application "Finder" to set finder to name of (files of folder fldr whose name starts with prefix)

-- Cleanup the files
-- Just for fun, delete the Finder created one with shell tools and delete the shell created one with Finder.
tell application "Finder" to (file |HFS name| of folder fldr) as alias
do shell script "rm " & quoted form of POSIX path of result
tell application "Finder" to delete (POSIX file ((POSIX path of fldr) & |POSIX name|) as alias)

{ls, finder} --> {{"demo-HFS:file:with:slashes.txt", "demo-POSIX:file:with:colons.txt"}, {"demo-HFS/file/with/slashes.txt", "demo-POSIX/file/with/colons.txt"}}