Process substitution in FreeNAS Bash shell

Status
Not open for further replies.

rhdinah

Dabbler
Joined
May 18, 2012
Messages
20
My goal is to do a "while read" command with process substitution of a find command.
Schematically:

while read ...; do
stuff​
done < <(find ...)

While I can make this work on Linux and my Mac, I cannot make it work on FreeNAS.

Simplifying: under Bash

echo >(true) ... works
echo <(true) ... works
wc <(cat file.txt) ... does not work ... terminates in a wc: /dev/fd/63: open: No such file or directory

I understand that process substitution is not POSIX compliant ... but the shell understands the first two commands without complaining about syntax ... the last command fails. I know you can use named pipes, but I'd rather not have to deal with two shells. I cannot find any information in the forums on this ... well there's one hit ... but not really the same.

Mac is supposedly BSD-based ... as might be FreeBSD, the father of FreeNAS ... so I'm wondering why I'm having luck with my Mac and not FreeNAS.

So if someone could give me some help here I'd really appreciate it! Thank you!
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
Is there any reason you can't use:

Code:
find ... | while read ...; do
    stuff
done
 

rhdinah

Dabbler
Joined
May 18, 2012
Messages
20
Is there any reason you can't use:

Code:
find ... | while read ...; do
    stuff
done

Thank you very much! This works great! I don't know why I didn't think of it other than all the internet examples of this type seemed to be involved around process substitution ... and ... so I just didn't let go of that especially since it worked so well in other bash shells.

So I wonder if this is an error in FreeNAS/FreeBSD bash ... or it is a "works as designed" thing ...

Thanks again fracai!
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,553
Thank you very much! This works great! I don't know why I didn't think of it other than all the internet examples of this type seemed to be involved around process substitution ... and ... so I just didn't let go of that especially since it worked so well in other bash shells.

So I wonder if this is an error in FreeNAS/FreeBSD bash ... or it is a "works as designed" thing ...

Thanks again fracai!
You're probably not actually using bash, which means scripts laden with bash-isms won't work as shown in most howtos.

Or to restate in a way that might make some people's eyes twitch, the default bash in freenas Linux doesn't work the same as bash in other linuxes. :D
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
No, it's definitely bash proper. I did however find this: https://github.com/andsens/homeshick/issues/124#issuecomment-63984418

"Oho. sudo mount -t fdescfs fdesc /dev/fd and now things are fixed.
@gavinatkinson, who knows more than I ever will, pointed out that bash now requires fdescfs(5) mounted on /dev/fd which FreeBSD does not yet do as default."

I don't know if this can be mounted in FreeNAS or in a jail.
 

rhdinah

Dabbler
Joined
May 18, 2012
Messages
20
@anodos ... "the default bash in freenas Linux doesn't ..."

FreeNAS is based on FreeBSD ... that is *not* Linux ... that is much closer to Unix than Linux ...

but thanks for your input ... :smile:
 
Status
Not open for further replies.
Top