To what extent does the variable expansion in a double quote work correctly?

Asked 1 years ago, Updated 1 years ago, 72 views

For example, suppose you created a pseudo cp in a shell script in the following format:

#!/bin/sh

content=$(cat"$1")
printf'%s\n'"$content">"$2"

In most cases, the difference between the contents of the file created in the path of the second argument and the original file specified in the path of the first argument disappears, but I wondered if it would work for any file.

Question

  • Once a variable receives a (standard) input, expands it in a double quote and writes it somewhere, does the output change from the original input?When will it change?

unix sh posix

2022-09-30 18:27

1 Answers

As with 0x00 where metropolis is answering,
If the end of the file is not a line feed code, the end of the copied file will be accompanied by a line feed code.


2022-09-30 18:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.