Re: How (or why) does this bash script snippet work?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12 Jan 2012 14:13:53, Anthony R Fletcher wrote:
> On 12 Jan 2012 at 14:02:50, Dean S. Messing wrote:
> > 
> > In a system script I find this snippet
> > 
> >   nodevs=$(< /proc/filesystems fgrep rootfs)
> > 
> > and don't understand the syntax.  According to the bash man page,
> > 
> > $(< file) is shorthand for $(cat file).  But then the above should read
> > 
> >   nodevs=$(< /proc/filesystems | fgrep rootfs)
> > 
> > However, the latter leaves $nodevs empty whereas the former puts the
> > stuff that fgrep processes into nodevs as it should.
> 
> 
> The command 
>  < /proc/filesystems fgrep rootfs
> 
> redirects the input from the file /proc/filesystems into the command
> "fgrep rootfs". You could rewrite this as
>   fgrep rootfs < /proc/filesystems
> 
> nodevs=$( command ) takes the result of the command inside the
> parentheses and assigns into the variable nodevs.

Ahh! A perfect explanation.   Thanks.

I did not realise (or, rather, think about) trying the entire command w/in $(...) on
the commandline.  The manpage says $(< file) is equivalent
to $(cat file), so I made the mathematically naive assumption that 
"< file" is equivalent to "cat file".

When "< file" didn't act like "cat file" on the commandline (which
I did try) I became confused.

Dean
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux