18

I saw the syntax in this question: Birth is empty on ext4

sudo debugfs -R "stat <$(stat -c %i /home/user/path/to/file)>" /dev/sda5

I know command substitution $() and ``.

I kind of vaguely know the <() and >() syntax.

But I've never seen <$()>.

So what does that do?

2
  • 1
    I think the < > is being passed to debugfs. Commented Feb 22, 2020 at 18:14
  • Quotes matter. <$(...)> would be shell syntax (not meaningful or valid, but shell syntax nonetheless) -- but inside double quotes, < and > are literal characters; the shell leaves them alone. Commented Feb 24, 2020 at 13:16

1 Answer 1

35

<$()> would be valid bash syntax for commands that read from a file (< part) where file names are created using command substitution ($() part) that redirect output to some other file (> part). Example:

$ echo text > FILE
$ wc < "$(echo FILE)" > WC_OUT
$ cat WC_OUT
1 1 5

However, in the answer you linked to <$()> is used in the parameters to debugfs. In man debugfs it says:

stat filespec

Display the contents of the inode structure of the inode filespec.

and:

The filespec argument may be specified in two forms. The first form is an inode number surrounded by angle brackets, e.g., <2>

In that case:

sudo debugfs -R "stat <$(stat -c %i FILE)>" /dev/sda5

would be expanded by the shell to the equivalent of this:

sudo debugfs -R "stat <4476834>" /dev/sda5

which is a valid debugfs command. Check it with echo:

$ echo sudo debugfs -R "stat <$(stat -c %i FILE)>" /dev/sda5
sudo debugfs -R stat <4476834> /dev/sda5
2
  • 1
    My mind is blown, I didn't check the man page of debugfs since I assumed that no bash command would parse an argument as <123456789>. Commented Feb 22, 2020 at 18:37
  • 11
    Technically, debugfs is not Bash commad, that is it's not Bash built-in command. It's an external program that could run in all shells, even in these that do not implement < and > and on multiple operating systems. Commented Feb 22, 2020 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .