Mam bash skrypt, w którym chcę przekazać użytkownikowi na standardowe wyjście, ale także wysyłać polecenia do sub-procesu poprzez deskryptor pliku - tak:Odmowa wydania deskryptora pliku z zastąpieniem procesu bash?
# ...
# ...
echo "Hello user, behold a cleared gnuplot window"
# pass the string "clear" to gnuplot via file descriptor 3
echo "clear" >&3
więc pomyślałem, może "to set up" po pierwszym uruchomieniu podproces takiego:
#!/bin/bash
# Initiate(?) file descriptor 3, and let it direct to a newly
# started gnuplot process:
exec >3 >(gnuplot)
Ale to daje błąd:
/dev/fd/63: Permission denied
is th należy się spodziewać?
Nie rozumiem, co się dzieje. (Robię coś złego może się zdarzyć, że mój system ma jakieś specjalne ustawienia zabezpieczeń, uniemożliwiając co usiłuję zrobić (Ubuntu Linux 12.10)?).
„Obejście” - dodaje się wydaje za równoważny z tym, co staram się zrobić, i działa bez błędów:
#!/bin/bash
# open fd 3 and direct to where fd 1 directs to, i.e. std-out
exec 3>&1
# let fd 1 direct to a newly opened gnuplot process
exec 1> >(gnuplot)
# fd 1 now directs to the gnuplot process, and fd 3 directs to std-out.
# I would like it the other way around. So we'll just swap fd 1 and 3
# (using an extra file descriptor, fd 4, as an intermediary)
exec 4>&1 # let fd 4 direct to wherever fd 1 directs to (the gnuplot process)
exec 1>&3 # let fd 1 direct to std-out
exec 3>&4 # let fd 3 direct to the gnuplot process
exec 4>&- # close fd 4
lub, jak jeden-liner:
#!/bin/bash
exec 3>&1 1> >(gnuplot) 4>&1 1>&3 3>&4 4>&-
dlaczego to działa, ale początkowa wersja nie jest?
Każda pomoc bardzo ceniona.
$ bash --version
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
[...]
Spróbuj '-C' flagę. – Tobu
man sudo ... "Opcja -C (blisko) pozwala użytkownikowi określić punkt początkowy powyżej standardowego błędu (trzy deskryptor pliku)." Więc jak mam to wykorzystać w powyższym kontekście? –