-4

Is there any Linux application that just prints whatever you give it WITHOUT doing ANY sort of interpretation? So regardless of what I send to it, it would always output exactly what I send to it?

I want something with the functionality of echo or printf, but without interpreting the \ and everything else.

Here's the kind of application I want:

newcommand "sa"" '' " "' ''""d f\sad\ f\sad\ \df\\ h\df\\\\\ sdf\h\sdfh\"" """" ''" " "ds\f\\\\ $%% \\as\ fsa\dg\ \afd\g\ \df\g \\df\g\\\\ n\ \n \\ sa\d \as \t a fsad g"" DF"G ""SD"F"" "DF"SG" """"Ds f"G" 'dsf'g 'sdf" G'ds f'g"SD fG"sd'f'g 'SFD""" ' > testfile1
cat testfile1
"sa"" '' " "' ''""d f\sad\ f\sad\ \df\\ h\df\\\\\ sdf\h\sdfh\"" """" ''" " "ds\f\\\\ $%% \\as\ fsa\dg\ \afd\g\ \df\g \\df\g\\\\ n\ \n \\ sa\d \as \t a fsad g"" DF"G ""SD"F"" "DF"SG" """"Ds f"G" 'dsf'g 'sdf" G'ds f'g"SD fG"sd'f'g 'SFD""" '

I can't find any program with this functionality. Basically, every positional parameter is outputted as is, including " and '. The only things that aren't outputted as-is would be |<> for obvious reasons

Okay, here's an even better example of what I want:

I want something that does, in command line and in one single line, something that can be achieved using nano or vi and writing one full line of text.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
iamAguest
  • 483
  • 2
    For context, see https://unix.stackexchange.com/questions/470303/ . Observe that in two of the answers printf is indeed outputting exactly what it is given, and \t comes out as \ followed by t. – JdeBP Sep 21 '18 at 08:37
  • That's not helping. Also this is for something else. – iamAguest Sep 21 '18 at 08:43
  • 1
    If you don't say why it's not helping we don't know in what direction you want to head instead. – Chris Davies Sep 21 '18 at 08:50
  • Then, given that you already have printf doing what you say that you want, and contradicting the question's premise that printf is not doing, you have not adequately expressed your question. – JdeBP Sep 21 '18 at 08:51
  • I don't mean to be rude or anything, but the title is pretty clear: I need a Linux application that does exactly what I wrote, print the text without any interpretation. All of the comments and answers are about using other applications and using escapes. That's NOT what the question is about... @JdeBP printf also interprets the strings you give it. I want something simple that never interprets anything. If you pass something to id, whatever it is, it would just output it back the same way you gave it, which then you can redirect. Basically, the functionality of echo without interprets. – iamAguest Sep 21 '18 at 08:52
  • You have that in printf. You even have several examples in answers of it doing exactly that, printing out its arguments with %s. The problem is indeed that your question is not clear, and an inadequate explanation of what you are asking for. – JdeBP Sep 21 '18 at 08:54
  • @JdeBP no, printf does NOT do what I asked. If it requires %s to do it, then it does NOT do what I ask. %s is printf INTERPRETING %s as something other than plain %s. What is my question? A program that DOESN'T interpret ANYTHING. Seriously, my question is not that hard! – iamAguest Sep 21 '18 at 09:00
  • No-one said that it was hard. We said that it was based upon an erroneous premise, unclear, and given that you reject the very thing that does what the question said that you wanted not adequately explaining what you wanted. And demonstrably so, given that it now reads differently. It now shows that you need to read https://unix.stackexchange.com/questions/412823/ and https://unix.stackexchange.com/questions/307011/ . – JdeBP Sep 21 '18 at 09:27
  • Stephane's answer basically cleared it to me. So the answer is that what I wanted is basically impossible because of shell restrictions. – iamAguest Sep 21 '18 at 09:29
  • How do you want to indicate the end of the text? – JigglyNaga Sep 21 '18 at 10:01
  • 1
    Why would an application that "doesn't interpret the text at all" behave any differently with |<> as input? How are you providing the input to this program? As arguments, or as stdin? – Jeff Schaller Sep 21 '18 at 10:56
  • cat is an application that doesn't interpret the text at all. If you want something like echo that outputs everything behind the echo unmodified, that's impossible. For details, look up how the shell processes command lines. – RalfFriedl Sep 21 '18 at 16:56
  • Voting to close as unclear because I can't understand why what seem to be perfectly valid answers are all being rejected as unacceptable. – Chris Davies Sep 21 '18 at 20:55

2 Answers2

3

Those ", \ are part of the shell syntax, they are not something that is passed to the command, the command cannot do anything about those.

The

printf %s 'foo " bar' "bar ' baz" > file

command line is code in the sh language (where the space, ', ", > characters have a specific meaning), it's not a line that it passes to the printf utility.

That's interpreted by the shell to run printf with %s, foo " bar and bar ' baz as arguments and its stdout redirected to file.

All printf sees is that list of arguments, it doesn't see the shell code (or python code if printf was called from python rather than a shell) that was used for it to be called with that list of arguments. printf %s will print each of those without doing any interpretation which will result in file containing foo " barbar ' baz.

Here you could use another shell syntax construct: the here-document, where the here-document delimiter is quoted, in which case, no interpretation is done:

cat << 'EOF' > testfile
"sa"" '' " "' ''""d f\sad\ f\sad\ \df\\ h\df\\\\\ sdf\h\sdfh\"" """" ''" " "ds\f\\\\ $%% \\as\ fsa\dg\ \afd\g\ \df\g \\df\g\\\\ n\ \n \\ sa\d \as \t a fsad g"" DF"G ""SD"F"" "DF"SG" """"Ds f"G" 'dsf'g 'sdf" G'ds f'g"SD fG"sd'f'g 'SFD""" '
EOF

The only restrictions on the text are:

  • except with zsh, it can't contain NUL bytes
  • it can't contain EOF on its own line (you can use a different delimiter if need be)
  • except when the text is empty, there will always be a trailing newline character added.

Or you could run:

cat > file

After which it's cat and no longer the shell that will take your user input, then you can enter the content as you wish and end with Ctrl+D.

As a hack, you could rely on the fact that shells don't do any interpretation of text in comment and retrieve the command line from the saved history and output what's past the #. For instance, with the bash shell, interactively:

fc -l -0 | cut -d '#' -f3- > testfile #the text here with \ ' "
2

It’s not a Linux-specific application, but cat does just that when run without arguments: it copies its standard input to its standard output, with no change.

Stephen Kitt
  • 434,908
  • I cannot redirect it to a file though. I want something with the functionality of echo or printf, but without interpreting the \ and everything else. – iamAguest Sep 21 '18 at 08:34
  • 4
    @iamAguest Use cat with a quoted here-document redirected into the file you want to write to. – Kusalananda Sep 21 '18 at 08:43