Shell mapfile - bash - not working

I wrote this in linux so I now am wondering does FreeBSD support it because it is not working, even though it's still bash. I put it in my startup script for desktops that use one and dockapps
Code:
mapfile -t startapps < $HOME/bin/userstartups/dockappsstartups
    for p in ${startapps[@]} ;
    do
        which "$p" >/dev/null && "$p" &
    done
the other file is just a plain text (flat file) list of dockapps
example
Code:
gkrellm
nm-applet
blueman-applet
wmbattery
wmwifi
wmwebcam
so do I have to just fall back to listing everyone of them separately in the startup file instead, or is there just a something missing in that bash code because this is fbsd?
 
I honestly didn't even know what 'mapfile' was.
The mapfile command is not very portable. That is, if you want to ensure your script can run on a wide array of systems, it's not recommended to use mapfile. It's provided primarily as a convenience. The same functionality can be achieved using a read loop, although in general mapfile performs faster.

because it is not working
Too vague. What's not working? Any error messages? Array not being filled? What exactly isn't "working"?

even though it's still bash.
Are you sure you're running this on bash(1)? Not sh(1)? On a lot of Linux distributions (not all of them) /bin/sh is actually bash in disguise. On FreeBSD it is not.
 
I honestly didn't even know what 'mapfile' was.



Too vague. What's not working? Any error messages? Array not being filled? What exactly isn't "working"?


Are you sure you're running this on bash(1)? Not sh(1)? On a lot of Linux distributions (not all of them) /bin/sh is actually bash in disguise. On FreeBSD it is not.
oh just to get this posted to answer the other questions

Code:
userx@FreeBeSD:~$ echo $SHELL
/usr/local/bin/bash

userx@FreeBeSD:~$ mapfile -t startapps < $HOME/bin/userstartups/dockappsstartups
userx@FreeBeSD:~$ echo $startapps[@]
pasystray[@]
userx@FreeBeSD:~$ echo $startapps
pasystray
 
Two useless cats? Is there any difference with

Bash:
while read foo; do
  somethingwith "$foo"
done < $HOME/bin/userstartups/dockappsstartups

No, I was hoping for that reply. FWIW I don't find the second form as readable, with the input specced after the done.
 
No, I was hoping for that reply. FWIW I don't find the second form as readable, with the input specced after the done.
A little known fact about shell grammar is that redirections can appear anywhere, even between arguments. Most people place them at the end of a command, as in cmd arg1 arg2 < in > out. But < in cmd arg1 > out arg2 is equivalent. So the loop in question could also be written as

Bash:
< $HOME/bin/userstartups/dockappsstartups while read foo; do
  somethingwith "$foo"
done

Some might prefer a backslash/newline after the long file name for even better readabilty.
 
Back
Top