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

Anthony R Fletcher arif at mail.nih.gov
Thu Jan 12 19:13:53 UTC 2012


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.

			Anthony.



More information about the users mailing list