-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.

13
  • 2
    For context, see 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. Commented Sep 21, 2018 at 8:37
  • That's not helping. Also this is for something else. Commented Sep 21, 2018 at 8:43
  • 1
    If you don't say why it's not helping we don't know in what direction you want to head instead. Commented Sep 21, 2018 at 8: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. Commented Sep 21, 2018 at 8:51
  • 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? Commented Sep 21, 2018 at 10:56

2 Answers 2

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 \ ' "
4
  • Thank you. So basically, there is no way any command would be able to redirect text as-is into a file, the same way you would just write it with vi or nano? Commented Sep 21, 2018 at 9:22
  • @iamAguest, I think you misunderstand what a shell command line is. See if the edit makes it any clearer. Commented Sep 21, 2018 at 9:40
  • Thanks, that's really the best answer here, but the only problem here is that I cannot do all that in just one line of text, which is what I was looking for. Commented Sep 21, 2018 at 9:44
  • @iamAguest, see edit for a hacky way. Commented Sep 21, 2018 at 10:33
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.

2
  • 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. Commented Sep 21, 2018 at 8:34
  • 4
    @iamAguest Use cat with a quoted here-document redirected into the file you want to write to. Commented Sep 21, 2018 at 8:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.