@ operator in inferno sh

28 views
Skip to first unread message

Edouard Klein

unread,
Dec 4, 2024, 5:09:02 AM12/4/24
to infer...@googlegroups.com
Hi all :)

I have trouble understanding how the @ operator works in sh.

sh(1) states:

@ command ...
Execute command in a subshell, allowing (for instance) the
name-space to be forked independently of main shell.


Now, on an Inferno prompt, here is what I try:
; memfs /mnt/ram
; echo coucou > /mnt/ram/greetings
; cat /mnt/ram/greetings
coucou
; cat /mnt/ram2/greetings
cat: cannot open /mnt/ram2/greetings: '/mnt/ram2/greetings' does not
exist
; # This was expected
; sh -c { bind /mnt/ram /mnt/ram2; cat /mnt/ram2/greetings }
coucou
# Now the ram2/greetings file existed in the subshell created by sh -c
# and the greetings appear
; cat /mnt/ram2/greetings
cat: cannot open /mnt/ram2/greetings: '/mnt/ram2/greetings' does not exist
# And this is also expected, as the initial namespace was not modified


So far, so good.

Now, with @:

; @ { bind /mnt/ram /mnt/ram2; cat /mnt/ram2/greetings }
coucou
; cat /mnt/ram2/greetings
coucou


Why was the original namespace modified ? Isn't @ supposed independently
fork the name-space of the main shell, as explained in the doc ?


Cheers,

Edouard.

Valery Ushakov

unread,
Dec 4, 2024, 11:09:54 AM12/4/24
to inferno-os
Subshell makes it possible to fork namespace, but you need to do it if
you want/need it.

  % @ { pctl forkns; bind /mnt/ram /mnt/ram2; cat /mnt/ram2/greetings }
  coucou
  % cat /mnt/ram2/greetings

  cat: cannot open /mnt/ram2/greetings: '/mnt/ram2/greetings' does not exist

Reply all
Reply to author
Forward
0 new messages