You are not logged in.
Pages: 1
Why wont this script work?
#!/bin/bash
TUT='ls /dev/video*'
if [ "$TUT" == "/dev/video1" ]; then
sh /home/jonas/camcycle2.sh
else
sh /home/jonas/camcycle.sh
fi
What i want it to do is to list all video-devices in /dev/ and if there is a /dev/video1 it will run camcycle2.sh, if there is no video1, run camcycle.sh.
Last edited by whacath (2010-06-17 14:22:14)
Offline
Because your logic is broken.
Also: you shouldn't be using ls
And you should learn to indent your code.
Last edited by Mr.Elendig (2010-06-17 14:23:16)
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
You want to execute camcycle.sh even if there is no video device?
#!/bin/bash
#
CAM=$(find /dev -name video1)
HDIR=/home/jonas
[ $CAM ] && sh $HDIR/camcycle2.sh || sh $HDIR/camcycle.sh
Last edited by demian (2010-06-17 14:42:10)
no place like /home
github
Offline
[ -e /dev/video1 ] && $HOME/camcycle2.sh || $HOME/camcycle.sh
Since /dev/video1 is a special file you could also use a different flag than -e, check the bash manpage (around l.2105) for more details.
EDIT: For the record the if/then construct you used is fine (with indenting or course), but since this is so simple a nice one-liner suffices.
Last edited by quigybo (2010-06-17 15:06:22)
Offline
@Mr.Elending: Yay for your extreme helpfulness. Instead of telling me what i should do or not do, explain instead!
@demian: No my tought is that if there is no video1 and there is a video0, camcycle.sh should kick in. Thanks for your example, i will have a look at it.
Offline
I just realised that this was posted in Community Contributions, you should have posted in Newbie Corner (thus avoiding responses such as Mr.Elendig's).
Back on topic: you can solve it with an if/elif chain and the -e test.
Offline
Then you should use the if construct:
if [ -e /dev/video1 ];then
$HOME/camcycle2.sh
elif [ -e /dev/video0 ];then
$HOME/camcycle.sh
fi
no place like /home
github
Offline
Could someone please move this? Why is this in community contributions in the first place, whacath? (There is a tiny chance I am mistaken as to the purpose of this section, however)
Offline
Moved.
Offline
FYI, you use TUT='ls /dev/video*' which would not capture the output of ls. You should have done TUT="$(ls /dev/video*)" to capture the output. That would have still been wrong if there were more than one video device in /dev. The correct logic to use is given by demian in post #7.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
Thanks guys!
So do you have any links or something to a good bash guide? becouse i really need to learn it the right way.
Offline
There are a good set of documents on TLDP. Here are a choice few: Advanced Bash-Scripting Guide, Bash Guide for Beginners, BASH Programming - Introduction HOW-TO.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
The TLDP guides are pretty dated, and fairly rough on a beginner if you're not aware of what you need to filter out (and you do need to filter some out). I highly recommend Greg's BashGuide. It's well written, simple, and provides excellent examples. The rest of the Wiki on the site is an absolutely phenomenal resource.
Offline
Pages: 1