Sponsored By

Sign in to follow this  
shanenin

Using The && Operater

Recommended Posts

I have this very simple script. If the first command fails, I want the script to stop. I thought the "&&" operater would do that. This is not stopping the script

#!/bin/bash

modprobe ath_pci &&
modprobe wlan_scan_sta
ifconfig ath0 up
iwconfig ath0 essid "linksys" key 6A4601E10F858AF350C545A658
dhcpcd ath0

why isn't the operater stopping the script. To test it I ran it as regular user. I would think that it would stop after the first command fails with an exit code of non one, but it does not.

Share this post


Link to post
Share on other sites

That script is equivalent to

$ modprobe ath_pci && modprobe wlan_scan_sta
$ ifconfig ath0 up
$ iwconfig ath0 essid "linksys" key 6A4601E10F858AF350C545A658
$ dhcpcd ath0

Share this post


Link to post
Share on other sites

thanks for making that more clear. I suppose I could do this

modprobe ath_pci || exit 1
modprobe wlan_scan_sta
ifconfig ath0 up
iwconfig ath0 essid "linksys" key 6A4601E10F858AF350C545A658
dhcpcd ath0

someone else reccomended I use the set command

set -e

Edited by shanenin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this