It does not work that way. $(<file) is a special case, which is a faster alternative to $(cat file). If you are using anything other than just a file, it becomes something else. $( ... ) is just command sustitution, so if we leave out that, it becomes:
This is the same as tr -dc '[:alnum:],@#:!?+-' < /dev/urandom | head -c10
This is strange, it effectively just means cat /dev/urandom | head -c10
This is the same as the first one with UUOC
This is equivalent to :< /dev/urandom | tr -dc '[:alnum:],@#:!?+-' | head -c10, which is that same as : : | tr -dc '[:alnum:],@#:!?+-' | head -c10
This User Gave Thanks to Scrutinizer For This Post:
It is. In fact, tr -dc etc. are interpreted as input files
and generate error messages which are suppressed in above case as /dev/urandom never ends and the pipe is chopped off by the head -c10 from the other side.
Yeah, I agree with you regarding the UUOC one.
The test with -- was just bulk try just to see if it would get the -- as an end of options and see how it would handle the rest of the command line.
I ran it on an AIX machine which didn't return an error message, but a fooled output instead, with some strange control character (the kind of output that sometimes may mess up your PuTTY screen ...)
As Yoda and Scruti noticed, I think the confusing point was that, $(< /dev/urandom tr -dc '[:alnum:],@#:!?+-' | head -c10 )
is not interpreted as the special case $(<filename) but as the $( cmd )
This brings me to the question :
Does the special case $(<filename) support only and strictly 1 file ?
This brings me to the question :
Does the special case $(<filename) support only and strictly 1 file ?
Passing more than one file to the redirection wont be interpreted that way, the second file will just be understood as a command name.
Using more than one redirection lead to undefined behavior.
- ksh ignores all redirections but the first one, i.e. output file1. It doesn't check file2 for readability/existence.
- bash silently ignores the whole command, i.e. output nothing, however, it returns an error if file1 or file2 isn't readable (or doesn't exists)
Obviously $( < filename ) copies the stream with a shell-internal, just like the external command $( cat < filename ) does.
For a concatenation of file1 and file2 you have to use the external command $( cat file1 file2 )
or a string concatenation like this:
Using more than one redirection lead to undefined behavior.
Perhaps this is just an aside, but wouldn't redirecting from a named pipe work? That is, if in $(< file1)file1 would be a named pipe being filled by cat file1 file2 ... ?
And second, wouldn't $(< $(cat file1 file2) ) also work? Right now i am travelling with this damn work-laptop and have no U*X-system at hand, so i can only speculate instead of trying....
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)
Hi All,
I have stumbled upon very unique issue. In my script I am doing cat file and then greping and cutting so as to assign the value to variable. My file is,
<mxc_tl_load_extractdata_prop.bsh>
DB_USER=test_oper
hostname=xxx
FTP_USER=test1_operate
MAIL_LIST=xxx@yyy.com... (1 Reply)
Hi,
I have two files
one.txt
laptop
boy
apple
two.txt
unix
linux
OS
openS
I want to split one.txt into one line each and concatenate it with the two.txt
output files
onea.txt
laptop (4 Replies)
I am looking for a command to take files with a specific date and cat them all into big file. I know I can use commands to list all of the files from a certain date. But I want to do that and take those files and make on large files containing all of them.
Any help would be great. This is being... (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)
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)
Hi,
I wnat to read a fiel line by line and store each line in a variabel, so I made a for loop:
for i in `cat file` ; do
#do sth.
done;
The problem is, that in the file, there are lines with only asterisks like this... (3 Replies)
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)