One reason might be that even though it will work in bash and ksh93, it is not POSIX compliant and so for portability it would be best to use $(cat file)
Yes. However, there is no need to save the contents of file in a variable. Just use the line:
in the here document instead of:
before the here document and:
in the here document.
---------- Post updated at 12:35 ---------- Previous update was at 12:22 ----------
Quote:
Originally Posted by Yoda
Scrutinizer, isn't that a command substitution form?
If so isn't it suppose to work on all POSIX shell?
No. The command substitution $(< file) as defined by the standard is the equivalent to the command:
executed in a subshell and the standard output of that command (which would be nothing) would be the expansion of the command substitution.
In theory, I'm not sure that the standards allow shells to actually produce any output in this case, but since it isn't the type of command you would expect to find in a standards conforming shell script, no one has complained. If someone did complain that a shell was non-conforming because of this construct, I'm sure the Austin Group would issue an interpretation saying that the standard is "clear and wrong" and either specify the current behavior in the next revision of the standard or explicitly state that the behavior is unspecified in this case (which would allow shells to continue to provide this extension).
These 2 Users Gave Thanks to Don Cragun For This Post:
Can you use cat to send the first 25 lines of a file to the printer? I'm thinking I can pipe it with '|' but I'm not school to check printer output.
With the 'nl' used, all lines are numbered on the print out, but how does one number only the blank lines?
Thanks:) (1 Reply)
Not sure how to do this exactly.. just want to take the first 100 lines of a file and cat it out into a second file. I know I can do a more on a file and > it into a different file, but how can I make it so only the first 100 lines get moved over? (1 Reply)
I want to cat a file with only show the line contain '/bin/bash' but don't show the line contain 'load' (don't show if the line contain 'load' and '/bin/bash' together), how to type in the command? thk a lot! (2 Replies)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
Hello All,
I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its
output in a ".txt" file.
Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file...
Data for Host-1 (192.168.1.110)
Checking the... (2 Replies)
Hello,
I'm on a remote computer by SSH. How can I get the output of "cat file" into a file on the local computer?
I cannot use scp, because it's blocked.
something like:
ssh root@remote_maschine "cat /file" > /locale_machine/file
:rolleyes: (2 Replies)