sapcal000
sapcal000

Reputation: 135

How can I make a file named "\$*'PNP'*$\" using touch command

How can I make a file named "\$*'PNP'*$\" using touch command? what I did:

% touch '"\$*'PNP'*$\"'
% ls 
"\$*PNP*$\"

I need ' beside P

Upvotes: 2

Views: 56

Answers (2)

user1934428
user1934428

Reputation: 22291

Just wrap it into single quotes:

touch '"\$*'PNP'*$\"'

Upvotes: 0

John1024
John1024

Reputation: 113924

One approach is to put the desired filename in a Try:

$ touch "\"\\\$*'PNP'*$\\\""
$ echo *PN*
"\$*'PNP'*$\"

If you run ls, be aware that it may put escapes in the file name:

$ ls
'"\$*'\''PNP'\''*$\"'

In the above touch command, escapes are required. First, to put a double-quote inside a double-quoted string, it must be escaped as \". Second to put a backslash in a double-quoted string, it must also be escaped as \\. Inside a double-quoted string, ' does not need to be escaped.

Alternative: single-quoted string

$ touch '"\$*'\''PNP'\''*$\"'
$ echo *PN*
"\$*'PNP'*$\"

The above has five strings:

  1. '"\$*'
  2. \'
  3. 'PNP'
  4. \'
  5. '*$\"'

Strings 1, 3, and 5 are single-quoted strings. Strings 2 and 4 are unquoted but escaped single-quotes.

Upvotes: 2

Related Questions