shell scripting question - echo \040

Got Haggis?

Veteran XX
so I need to echo a windows directory that has a space c:\program files

which would normally be something like

echo "C:\Program\040Files"

and that will have the space. The problem is I need to actually echo out the \040 - I thought escaping it, like echo "C:\Program\\040Files" would work, but it doesn't.

What is the correct way to do this?
 
Not sure I understand, but can you echo the 8.3 name?

"C:\Progra~1\040Files"
 
\040 = space

when that echo's out, it will have a space instead of the \040 (I am writing this to another file, so I don't want the space, I actually want the \040 portion of the string printed out

it's actually not program files, i'm just using that as an example, I don't think I can use the 8.3 name
 
I don't understand, what shell are you using?

Why can't you just echo a space:

$ echo "c:\program files"
c:\program files

or whatever you want to echo:

echo "c:\program\040files"
c:\program\040files
 
because this is a linux terminal server - where nothing is run on the client..and basically i need to write some stuff to the clients fstab , which i do by running a shell script on the server

in the fstab file, when mounting a directory with a space in it, it will not work if you just put

//netdrive/program files /shares/netdrive

you must use

//netdrive/program\040files /shares/netdrive

so when my script writes to the 'virtual' fstab file, it doesn't mount correctly when there is a space. but if it would actually print out the octal code for space /040, then everything work work perfectly.
 
The DOS interpreter is not going to recognize your "\040" as a space character. I don't think it will even recognize code page characters, Unicode nor HTML.

You *might* be able to assign an ANSI escape sequence to an environment variable but that used to involve loading ANSI.SYS at startup. I haven't played with that stuff in decades.


Edit: Linux. nm. You didn't state that.
 
Last edited:
$ echo //netdrive/program\\040files /shares/netdrive > test
$ cat test
//netdrive/program\040files /shares/netdrive


So what exactly is the fucking problem?
 
echo "//netdrive/program\\040files /shares/netdrive" >> /etc/fstab

will show up in /etc/fstab as

//netdrive/program files /shares/netdrive
 
yeah that was my first thought however apparently its not an option. If there is no easy way to do this (I don't do a lot of shell scripting at all) - then I may just point to one directory level before the one with the space in it.
 
so you want your script to actually output (eg)"C:\Program\040Files" into the sample fstab?

man fstab said:
The second field, (fs_file), describes the mount point for the filesys-
tem. For swap partitions, this field should be specified as ‘none’. If
the name of the mount point contains spaces these can be escaped as
‘\040’.

Ok... so.. just replace the space with "\040"

ie:

sed -e s/\ /\\\\040/g

(yes, that's 4 backslashes)
 
Back
Top