1

I am pretty sure this will be a duplicate, because I have seen it sometimes at other places, but I do not remember where and I also (obviously) do not know how it is called.

In an other SO post, there is this piece of code (bash):

obj(){
    . <(sed "s/obj/$1/g" obj.class)
}

What does . < do ? If it has a name, what is it ?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Itération 122442
  • 2,644
  • 2
  • 27
  • 73
  • 2
    Two different things. `<()` is **process substitution** where the output of the command inside is connected to a file that's usually an argument to another command. The period is an alias for `source`. They're both explained more in the bash manual. – Shawn Jul 07 '21 at 07:38
  • It takes the file `obj.class` and replaces every occurrence of `obj` in that file with the parameter you pass to this function. It then `sources` the result into your current shell. – Mark Setchell Jul 07 '21 at 07:51
  • Also note that if you're still stuck on bash 3, this won't work. See https://stackoverflow.com/q/32596123/9952196 – Shawn Jul 07 '21 at 07:52

2 Answers2

1

Source . [Docs]

Read and execute commands from the filename argument in the current shell context.

source is a synonym for dot/period . in bash, but not in POSIX sh, so for maximum compatibility use the period.


Process Substitution < () [Docs]

Process substitution allows a process’s input or output to be referred to using a filename.

0stone0
  • 34,288
  • 4
  • 39
  • 64
0

Type this into your terminal:

help .

The function obj takes one argument. It executes sed and replaces all occurrences of obj in the file obj.class with the argument. The result is used as Bash code and gets evaluated by the running Bash instance.

ceving
  • 21,900
  • 13
  • 104
  • 178