You are not logged in.
###### Samsung NC10 Commandcenter ######
#!/bin/bashcommand=""
act=""
args=0
param=$2if [ $# -eq 2 ]; then
args=2
fiadd () {
if [ args!=2 ]; then
echo "What do you want to activate?"
echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
read act
fi
if [ args=2 ]; then
act=$param
fi
case $act in
1)
echo "Activating LAN."
modprobe sky2;
/etc/rc.d/network start;
;;
2)
echo "Activating WLAN."
modprobe ath5k;
/etc/rc.d/network start;
;;
3)
echo "Activating Bluetooth."
modprobe btusb;
modprobe bluetooth;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}remove () {
if [ args!=2 ]; then
echo "What do you want to inactivate?"
echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
read act
fi
if [ args=2 ]; then
act=$param
ficase $act in
1)
rmmod sky2;
/etc/rc.d/network stop;
;;
2)
rmmod ath5k;
/etc/rc.d/network stop;
;;
3)
rmmod btusb;
rmmod bluetooth;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}cmd () {
if [ args!=2 ]; then
echo "What action do you want to perform?"
echo -e "1) Suspend(RAM)\t2) Hibernate(HDD)"
read act
fi
if [ args=2 ]; then
act=$param
fi
case $act in
1)
echo "Suspending to RAM."
pm-suspend;
;;
2)
echo "Hibernating to HDD."
pm-hibernate;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}if [ $# -ne 0 ]; then
case $1 in
add)
command=1
;;
rm)
command=2
;;
cmd)
command=3
;;
*)
command=$1
;;
esac
fiif [ $# -eq 0 ]; then
echo -e "Entering interactive mode. \nWhat task would you like to perform? \n1) Activate\t2) Inactivate\t3) Command"
read command
ficase $command in
1)
add
;;
2)
remove
;;
3)
cmd
;;
*)
echo "Invalid parameter '$command'!"
esac
I'm trying to make a script to control the various functions of my awesome netbook, but even though my design is ingenious , it doesn't work. I've tried everything and I just don't see why it can't work.
If you start it without arguments, it will ask interactively for the arguments and it works. It works if you pass the first argument, it asks you straight for the second one.
But it doesn't work if you give both arguments directly. I've tried pretty much everything and I'm about to start punching in walls.
It's my first real bash script though...
Last edited by initbox (2009-03-08 16:00:20)
Offline
this: "if [ args!=2 ]; then" (for example) doesn't look like bash... Try something like:
if [ $args -ne 2 ]; then
Offline
I have not tried it out. Here are some tips:
#!/bin/bash must be on line 1 to make any sense, but in this case it doesn't matter, because the default is /bin/sh
if [ x=y ] is assignment and will always succeed, it should be if [ x = y ]
Offline
Hmm. Never mind. I just realised I need to have $ in the if-variables.
And now it actually works! Yay.
Last edited by initbox (2009-03-08 15:56:01)
Offline
What is happening is that args is uninitialized. So it interprets:
[ -ne 2 ]
What you should do is:
[ -n "$args" -a $args -ne 2 ]
So it interprets first
[ -n "" ]
Which fails (edit: Which is false, rather)
Also mind the quotes. This is not what you want:
[ -n ]
That is always true.
Last edited by Procyon (2009-03-08 15:55:16)
Offline
if [[ $args != 2 ]]; then
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
Now it works!
All I had to do was add $ in the if-variables and add spaces into the if-conditions.
Thanks guys.
Use it if you find it useful, don't care about credits or w/e.
Finished script:
#!/bin/bash
###### Samsung NC10 Commandcenter ######
command=""
act=""
args=0
param=$2if [ $# -eq 2 ]; then
args=2
fiadd () {
if [ $args -ne 2 ]; then
echo "What do you want to activate?"
echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
read act
fi
if [ $args = 2 ]; then
act=$param
fi
case $act in
1|lan)
echo "Activating LAN."
modprobe sky2;
/etc/rc.d/network start;
;;
2|wlan)
echo "Activating WLAN."
modprobe ath5k;
/etc/rc.d/network start;
;;
3|bt)
echo "Activating Bluetooth."
modprobe btusb;
modprobe bluetooth;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}remove () {
if [ $args -ne 2 ]; then
echo "What do you want to inactivate?"
echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
read act
fi
if [ $args = 2 ]; then
act=$param
ficase $act in
1|lan)
/etc/rc.d/network stop;
rmmod sky2;
;;
2)
/etc/rc.d/network stop;
rmmod ath5k;
;;
3)
rmmod btusb;
rmmod bluetooth;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}cmd () {
if [ $args -ne 2 ]; then
echo "What action do you want to perform?"
echo -e "1) Suspend(RAM)\t2) Hibernate(HDD)"
read act
fi
if [ $args = 2 ]; then
act=$param
fi
case $act in
1)
echo "Suspending to RAM."
pm-suspend;
;;
2)
echo "Hibernating to HDD."
pm-hibernate;
;;
*)
echo "Invalid action '$act'!"
;;
esac
}if [ $# -ne 0 ]; then
case $1 in
add)
command=1
;;
rm)
command=2
;;
cmd)
command=3
;;
*)
command=$1
;;
esac
fiif [ $# -eq 0 ]; then
echo -e "Entering interactive mode. \nWhat task would you like to perform? \n1) Activate\t2) Inactivate\t3) Command"
read command
ficase $command in
1)
add
;;
2)
remove
;;
3)
cmd
;;
*)
echo "Invalid parameter '$command'!"
esac
Last edited by initbox (2009-03-14 12:12:26)
Offline