I am trying to use fbi in a bash script to display a series of .jpg images. But once fbi begins its process, it continues to cycle through the images and I only want to display each image once for a set period of time.
Asked
Active
Viewed 4,845 times
2
Gilles 'SO- stop being evil'
- 807,993
- 194
- 1,674
- 2,175
Steve B
- 21
- 1
- 2
-
Please consider adding a link to the homepage of the tool you are using (or, some information about it, at least; e.g., the version). – HalosGhost Jun 20 '14 at 05:27
-
I am try to display a series of .jpg imagaes running Linux on a RaspberryPi with a single line bash script. – Steve B Jun 23 '14 at 04:59
-
It seems like this would be better suited for a program that can handle multiple files from the get-go. For example, I would recommend [`sxiv`](https://github.com/muennich/sxiv). – HalosGhost Jun 23 '14 at 05:03
-
I am try to display a series of .jpg images running Raspian Gnu/Linux7 on a RaspberryPi with a single line bash script. The single command is "sudo fbi -noverbose -m 640x480 -t 1s /boot/images/0.*.jpg" and it continuously cycles through the set of images and can be stopped with a keyboard "esc" input, but I want to stop it after a set time interval. – Steve B Jun 23 '14 at 05:06
-
This is much, much harder to do with bash than it is with a real program. – HalosGhost Jun 23 '14 at 05:07
-
I can appreciate that, but unfortunately there are other factors involved as I need to have this part of a larger program that is monitoring manual (non keyboard) button pushes, etc. – Steve B Jun 23 '14 at 05:10
-
Then what you want is a window manager. Also, "non-keyboard button pushes" is an odd expression. What buttons are you referring to? – HalosGhost Jun 23 '14 at 05:12
-
The R-Pi must also monitor voltage input using GPIO and that input alters which images are displayed. All that works correctly if I can simply "stop" the fib process at regular intervals. – Steve B Jun 23 '14 at 05:21
-
1This appears to be an example of the [XY Problem](http://mywiki.wooledge.org/XyProblem). If you want to view the images like so, you could easily use a loop in a shell script and break after a given time lapse. However, it doesn't seem like this is your real issue, but rather a solution that you've come up with to work around the real issue even though it may not be the best option. – HalosGhost Jun 23 '14 at 17:30
-
My limited Linux experience is demonstrated with this question. All I know is that once my bash shell script executes the fib command, the only way it stops is by hitting "esc" on the keyboard. Thanks for you attempts to assist - I'll just keep trying. – Steve B Jun 23 '14 at 20:26
1 Answers
2
Disclaimer: I didn't actually test this with fbi, I used watch with a bunch of text files (watch displays text, not images, but it also runs until it's killed, like fbi), so in theory this (or similar) technique should also work with fbi.
#!/bin/sh
# Where are the files?
IMG_PATH="/foo/bar/fred/"
cd $IMG_PATH
# File list. Can either be hard-coded, space separated,
# or to use the output of a command, use $(command). The
# safest approach is to use a shell glob as I have done here.
FILE_LIST=*.txt
# How long to run the command in seconds before killing it?
TIMEOUT=1
# For every file on the list...
for FILE in $FILE_LIST
do
# OK, this is where the magic happens...
# First invoke a shell and feed the mini script (in double quotes)
# to that shell. The mini script first executes fbi with whatever
# filename is now set to $FILE by the loop, meanwhile, whatever is
# in brackets gets executed simultaneously (sleep for $TIMEOUT seconds
# then force kill the second shell and all its children, including fbi).
# What the heck is \$\$? Well, $$ normally refers to the process ID
# of the script itself. But we don't want to kill the main script with
# the for loop - we want to loop to go on. So we escape the $$ with
# backslashes like so \$\$ so that literally "$$" gets passed to the
# second subshell, so it kills only itself (and fbi as its child).
#########################
# You can add parameters to fbi if you need to.
# Also you may want to try removing the -9 parameter to kill in
# case it messes up your framebuffer... not sure how well fbi
# handles a forceful (-9) vs. graceful (no -9) kill.
sh -c "(sleep $TIMEOUT; kill -9 \$\$) & exec fbi $FILE"
done
I hope that this at least points you in the right direction... :)
terdon
- 234,489
- 66
- 447
- 667
Rouben Tchakhmakhtchian
- 950
- 5
- 9
-
1I changed your `ff=$(ls *txt)` to `ff=*txt`. Using `ls` that way breaks on even the simplest of strange names, try it on a filename that contains a space for example. As a general rule, you should always avoid using `ls` to generate a list of file names. `ls` is designed to be read by humans, not parsed. For more info see [here](https://duckduckgo.com/l/?kh=-1&uddg=http%3A%2F%2Fmywiki.wooledge.org%2FParsingLs) and [here](http://unix.stackexchange.com/q/128985/22222). – terdon Jun 20 '14 at 09:13