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.

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
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...