Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What is the difference between using _< and < for stdin when using process substitution. This is done using bash.

Example:

read bytes _< <(du -bcm random_iso.iso | tail -1); echo $bytes
share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

That's not a _< operator, that's a _ argument to pass to read and the < redirection operator. <(cmd) itself is process subtitution (that expands to a filename that points to a pipe).

What that does is run:

read bytes _  < /proc/self/fd/x

Where the fd x is the reading end of a pipe.

At the other (writing) end of the pipe, a background subshell process is executing du -bcm random_iso.iso | tail -1 with its stdout redirected to that pipe.

So read will store in the $bytes variable the first word of the last line of the output of du -bcm, and the rest of the line in the $_ variable.

Now I don't know where that du -bcm makes sense. None of -b, -c nor -m options are standard. While -c is quite common and is for giving the cumulative size, with GNU du, -b is to get the file size (not disk usage) in bytes, while -m is to get the size rounded up to the next mebibyte so they would be conflicting options (though maybe they used -b for its side-effect of enabling --apparent-size). FreeBSD du has -m (for mebibytes), no -b, Solaris has neither...

It looks like it was meant as a convoluted way to write:

wc -c < random_iso.iso

Or:

du --apparent-size -cm random_iso.iso | awk 'END{print $1}'

If they indeed wanted the file size rounded up to the next mebibyte on a GNU system.

share|improve this answer
    
The command is used at 26:44 in youtube.com/watch?v=CQ6kD48WMxc#t=26m44s - I believe they were just looking to get the size of the iso in MB. –  Steel City Hacker 20 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.