Sunday, April 10, 2011

How to Make a Shell Script in Linux?

Yeah, like you say, it's for newbie only :D. We will make a shell script to display voltage in mV and current in mA like I post before. Shell script can contain one or more lines of instruction usually issued in Terminal.

# Open your editor (I always choose vi) type:
#!/bin/bash
cat /proc/acpi/battery/C1AC/state | grep "present voltage"
cat /proc/acpi/battery/C1AC/state | grep "present rate"
# Don't forget to replace "C1AC" with your own battery type

# Save these shell script, for example, myfile.sh

# Change the mode of file so that it can be executed
chmod +x myfile.sh
# Run this script by typing this instruction in your Terminal:
./myfile.sh
# The output will look like this:
present voltage:         16778 mV
present rate: 702 mA
Shell script will simplify our life. Believe me and enjoy!

No comments: