Skip to contentSkip to conversation

A Good Question.

DISCUSSION Scott@Charter 6 participants 6 messages Mar 31, 2004

lore
Share & tools
lore
#0 lore raw

1. How would you create a file named "--help"?
I actually created a the file by doing something like touch test >>--help. But I think there is a "proper" way to create it?

2. How would you remove a file named "--help"?

Scott D. Smallsreed
3030 Chipmunk Dr.
Washoe Valley, NV 89704
775.849.8411 Hm
775.849.8412 Fax
775.722.7773 Cell

BEGIN:VCARD
VERSION:2.1
N:Smallsreed;Scott
FN:Scott Smallsreed
TEL;HOME;VOICE:775-849-8411
TEL;HOME;FAX:775-849-8412
ADR;HOME:;;3030 Chipmunk Dr.;Washoe Valley;Nevada;89704;US LABEL;HOME;ENCODING=QUOTED-PRINTABLE:3030 Chipmunk Dr.=0D=0AWashoe Valley, Nevada 89704=0D=0AUS EMAIL;PREF;INTERNET:[email protected]
REV:20040331T055544Z
END:VCARD

#1 lore raw
Quoted 3 lines · At 3/30/2004 09:55 PM -0800, Scott@Charter wrote:

1. How would you create a file named "--help"?
I actually created a the file by doing something like touch test >>--help. But I think there is a "proper" way to create it?

Commands that interpret --help as an option should (but might not) support -- to indicate "end of options" and all arguments following are to be interpreted as "non-option". Which means if the command takes a list of files as arguments you can force it to recognize arguments beginning with - as files by preceeding them with --. For example, the following hypothetical command line:

        $ somecommand --someoption --another -- --justafile --notanoption 
--help

should treat --someoption and --another as options, but --justafile --notanoption and --help should be treated as files (or whatever somecommand wants to use those arguments for).

If touch tries to interpret --help as an option, then "touch -- --help" should treat --help as a filename.

Quoted 1 line

2. How would you remove a file named "--help"?

Likewise, "rm -- --help" should remove filename --help

You could also use a partial or absolute path to the file, e.g.:

        $ touch ./--help
or
        $ touch $PWD/--help

If in doubt, sticking "./" in front of a filename in the current directory can simplify ornery cases like this.

Bonus problems:
How to create and delete file names with spaces or control characters? How about slashes (not as a directory delimiter) in the filename?

--
Jeff Woods <[email protected]>

#5 lore raw
In reply to Scott@Charter

touch ./--help
rm ./--help

Best regards,
Bostjan

Quoted 15 lines · On Wednesday 31 of March 2004 07:55, Scott@Charter wrote:

1. How would you create a file named "--help"?
I actually created a the file by doing something like touch test >>--help. But I think there is a "proper" way to create it?

2. How would you remove a file named "--help"?

Scott D. Smallsreed
3030 Chipmunk Dr.
Washoe Valley, NV 89704
775.849.8411 Hm
775.849.8412 Fax
775.722.7773 Cell

#2 lore raw
In reply to Jeff Woods

Jeff Woods [Tue, Mar 30, 2004 at 11:28:28PM -0700]:

Quoted 3 lines

[...]
Bonus problems:
How to create and delete file names with spaces or control characters?

with spaces: rm "file with spaces" (quoted as one arg) with control charaters: perpaps with their octal representation?

Quoted 1 line

How about slashes (not as a directory delimiter) in the filename?

slashes aren't iirc allowed in filenames on unix filesystems. (and wouldn't make any sense either, as they are defined _as_ limiter, you cannot escape them)

Nico

ps: I don't think any FAT/NTFS version can handle slashes either. But this is a guess.

#3 lore raw
In reply to Jeff Woods
Quoted 2 lines · Jeff Woods

Bonus problems:
How to create and delete file names with spaces or control characters?

Use single quotes; within single quotes, all characters are treated literally, except for the terminating quote. If the filename contains any single quotes, use '\'' (quote, backslash, quote, quote), e.g.

	rm 'foo'\''bar'

will remove a file called foo'bar.

However, note that this issue is due to the shell; it doesn't apply when passing arguments directly via e.g. execve(). OTOH, filenames which look like options are due to the command itself.

Quoted 1 line

How about slashes (not as a directory delimiter) in the filename?

Not possible. A filename cannot contain a slash; this is enforced by the kernel. If you encounter a filename which contains a slash, the filesystem is corrupted.

Signature · 1 line
Glynn Clements <[email protected]>
#4 lore raw

For spaces:
#touch my\ test
#touch 'my test'

#less my\ test
#less 'my test'

For backslashes:
#touch my\\test
#touch 'my\test'

#less my\\test
#less 'my\test'

Forward slashes aren't allowed by the kernel.

~Brad