0

I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name.

The problem is that I am not getting the expected results.
I am using the scape bar to scape the symbols, but when I list the name of the file this appears with unexpected single quotes at the beginning and the end of the file name and scape bars surrounded by single quotes before the single quotes that are supposed to be part of the file name. This is a bit confusing, I'll show you:

$ echo > \"\\\?\$\*\'\'\*\$\?\\\"

I expect this:

$ ls
"\?$*''*$?\"

but I get this instead:

$ ls
'"\?$*'\'''\''*$?\"'

I've tried to do it in other ways such as wrapping the double quotes in single quotes and viceversa, but I always get the same result. I already had made the same excercise in other computer and it worked perfectly. What is more intriguing is that I've discovered that both the single and the double quote work as a command to redirect to the standard input, what, I suspect, has to do with the unexpected name display:

$ '
>

$ " >

The commands don't seem to work for anything else than to display the standard input. Is this normal at all? What is going on? What can I do?

MC68020
  • 7,981
Daniel
  • 11
  • 1
    use ls -N to print the filename literally ... see https://unix.stackexchange.com/q/258679 – don_crissti Dec 15 '23 at 21:39
  • Thank you very much, that actually works!, but I want to get to the bottom of this, why do the quote characters work as commands? – Daniel Dec 15 '23 at 21:45
  • They don't, > is the continuation prompt... see https://unix.stackexchange.com/q/158997 – don_crissti Dec 15 '23 at 21:49
  • @Daniel not quite sure how to interpret your question there, but ls without -N just tries to quote "problematic" file names as necessary. – Marcus Müller Dec 15 '23 at 21:49
  • Now I get it, thank you very much! I have one last question. Why is that when I've worked in other computers I didn't need to include -N to display the list as I expected, is just a matter of configuration? – Daniel Dec 15 '23 at 21:55
  • 1
    It's a matter of ls version. See Padraig Brady's answer to the question I linked to in my 1st comment... It's also possible that same ls version was aliased to ls -N then yes, it's a matter of configuration... – don_crissti Dec 15 '23 at 21:59
  • Please take your found solution and post it as an answer to this question, and mark it as resolved. This will aid future searchers in that it will show that a solution has been found, and also not draw other folks here to answer something that already has been answered. – DopeGhoti Dec 15 '23 at 23:29
  • 1
    @DopeGhoti ok, thank you, I will. Apparently I have to wait for 10 hours before I can mark the issue as resolved. – Daniel Dec 17 '23 at 10:52

1 Answers1

1

It seems that I expected ls to work as ls -N. It seems in other machines the expected behaviour was different due to version or maybe configuration issues. About the quotes, it seems that they are not commands, but the prompt appears when the quotes are not properly closed as it interprets it as unfinished. All the explanations and relevant links are in the comments, thanks to @don_crissti and @Marcus Müller.

DopeGhoti
  • 76,081
Daniel
  • 11