More on variables, more array

Agustus 26, 2006

yes, its a brain cracker for me 🙂

to day i try again to finish the exercise to gain a bit more knowledge about bash scripting. this script is still dirty and if you have any other idea how to make it better than i will be happy to try it. I try to use conditional and looping together to get better result for the goal, but i think i failed a bit, especially at the back (b) job. But i hope i got more idea about how to handle array variable at bash scripting which i think a bit tricky ;).

this is the script:

#!/bin/bash
#
# web-browser.sh
# This script simply used wget and links to
# browser the user given address.
# The last 10 URLs entered by the user are stored in an array,
# from which the user can restore the URL by using the back functionality.
#
# note: remove # at the beginning links -dump ${ADDR[0]} command
# so the script can do the job as it should.

declare -a ADDR
declare -i a
declare -i i

a=0

while true; do

echo “This script will act as a simple text web browser,”
echo “press q to quit, b for back,”
echo -n “or please give the web address: ”
read choice
Baca entri selengkapnya »


More on variables, array

Agustus 14, 2006

Tugas latihan dari belajar bash kali ini mengenai variable, terutama sekali tentang array. Array merupakan salah satu jenis variable yang istimewa karena dapat di “isi” dengan kapasitas yang tidak terbatas (teoritis).

Setelah beberapa hari membaca dan melatih bagaimana variable di pergunakan dan dioperasikan dalam script bash, maka ini adalah salah satu tugas latihannya:

+ Write a script that does the following:

  • Display the name of the script being executed.
  • Display the first, third and tenth argument given to the script.
  • Display the total number of arguments passed to the script.
  • If there were more than three positional parameters, use shift to move all the values 3 places to the left.
  • Print all the values of the remaining arguments.
  • Print the number of arguments.

Test with zero, one, three and over ten arguments.

Saya buat seperti ini, my script is:

#!/bin/bash
#
# display_it.sh
# This script will display and manipulate argumen wich given to script…
# This script use array variable to store the argument.

declare -a ARGM

echo “This script you are using is: $0” | sed ‘s/.\///’
echo “You passed $# argument(s).”
ARGM=($@) #($@) equal to ($1 $2 $3 … $($#))

Baca entri selengkapnya »


Repetitive Tasks’ Exercise

Agustus 10, 2006

Since my skill in programming and scripting is fairly poor, then for that matters i encourage myself to learn bash scripting, one of scripting language that is easy to learn. Well, yes, since i start learning this script, soon i realize that i got more advantage from it. With knowledge in bash scripting, i get more ease to finish my every day task on computing, beside my system administration task too.

I think people which need to go more on linux nor any other operating system that utilized bash, should consider to learn bash scripting, its a quite fun to learn and see your life on computing will be more easy to do.

This week i learn more about repetitive task on bash, and there are exercise need to be done. For your info, this script run on Nexenta alpha5 which powered by OpenSolaris kernel, but i think it will not too differ in any operating systems.
Exercise:

  • Prints a list of servers to check, such as Apache, the SSH server, the NTP daemon, a name daemon, a power management daemon, and so on.
  • For each choice the user can make, print some sensible information, like the name of the web server, NTP trace information, and so on.
  • Optionally, build in a possibility for users to check other servers than the ones listed. For such cases, check that at least the given process is running.

Baca entri selengkapnya »