I've recently, (today) gotten into shell scripting. I've written three scripts today, I'll post them here and let you guys discuss them.
We'll start with helloworld.sh.
#!/bin/bash
echo "Hello world bash script!"
echo "Writen by krazed of x86!"
echo "The first of many. :P"
#this script is pointless, shush.
#what directory are we in!?
pwd
#what's in this directory!?
ls
#and, what's the uptime on this boxs?
uptime
#how about the processes being ran?
ps -aux
#Okay, that's all for today, 'folks.
#Written by krazed of x86.
#E-Mail: krazedx86@gmail.com
#AIM: krazedx86
This is called cmdlisting.sh. It takes the contents of the command directorys and lists them into three different .txt files.
#!/bin/bash
echo "Command listing bash script."
echo "Purpose: Copy your command lists to three different text files."
# First, we start off with /usr/bin, the default commands.
ls /usr/bin > defaultcommands.txt
echo "Contents of /usr/bin written to defaultcommands.txt"
echo " "
# Okay, now we have copied the contents of /usr/bin into the file defaultcommands.txt, Next!
# Now, time for /bin, the system commands.
ls /bin > systemcommands.txt
echo "Contents of /bin written to systemcommands.txt"
echo " "
# Okay, contents of /bin are now in systemcommands.txt
# Let's move on to /usr/X11/bin, the X windows programs.
ls /usr/X11/bin > xwincommands.txt
echo "Contents of /usr/X11/bin written to xwincommands.txt"
echo " "
# Alright, last but not least, let's list your installed programs. /usr/local/bin
ls /usr/local/bin > installedprograms.txt
echo "Contents of /usr/local/bin written to installedprograms.txt"
echo " "
echo "Script executed, no errors, not bad for my second script ever, eh?"
# Okay, that's the script for yah.
# It's not too bad for my second script ever.
# This script written by krazed of the x86 crew.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86
And, this is the third one. This one is actually pretty nifty, it's me experimenting with ANSI color codes, and scripting in color.
#!/bin/bash
# A small shell script written so I could fuck around
# and get the hang of coding with colors in shell scripts.
# A full list of all the ANSI color codes.
#1m - Change text to hicolour (bold) mode
#4m - " " " Underline (doesn't seem to work)
#5m - " " " BLINK!!
#8m - " " " Hidden (same colour as bg)
#30m - " " " Black
#31m - " " " Red
#32m - " " " Green
#33m - " " " Yellow
#34m - " " " Blue
#35m - " " " Magenta
#36m - " " " Cyan
#37m - " " " White
#40m - Change Background to Black
#41m - " " " Red
#42m - " " " Green
#43m - " " " Yellow
#44m - " " " Blue
#45m - " " " Magenta
#46m - " " " Cyan
#47m - " " " White
#49m - " " " Default background
#7m - Change to Black text on a White bg
#0m - Turn off all attributes.
echo -e "\x1B[34;49m This is blue text on default background."
echo -e "\x1B[32;49m This is green text on default background."
echo -e "\x1B[37;42m This is white text on green background."
# This script written by krazed of the x86 crew.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86
I re-wrote cmdlisting.sh so I could practice getting color codes down. So here it is, the new and improved, cmdlistingv2.
#!/bin/bash
echo -e "\x1B[34;49m" "Command listing bash script, version2. Rewritten 05/22/05."
echo -e "\x1B[34;49m" "Purpose: Copy your command lists to four different text files."
echo " "
# First, we start off with /usr/bin, the default commands.
ls /usr/bin > defaultcommands.txt
echo -e "\x1B[31;49m" "Contents of /usr/bin written to defaultcommands.txt"
echo " "
# Okay, now we have copied the contents of /usr/bin into the file defaultcommands.txt, Next!
# Now, time for /bin, the system commands.
ls /bin > systemcommands.txt
echo -e "\x1B[31;49m" "Contents of /bin written to systemcommands.txt"
echo " "
# Okay, contents of /bin are now in systemcommands.txt
# Let's move on to /usr/X11/bin, the X windows programs.
ls /usr/X11/bin > xwincommands.txt
echo -e "\x1B[31;49m" "Contents of /usr/X11/bin written to xwincommands.txt"
echo " "
# Alright, last but not least, let's list your installed programs. /usr/local/bin
ls /usr/local/bin > installedprograms.txt
echo -e "\x1B[31;49m" "Contents of /usr/local/bin written to installedprograms.txt"
echo " "
echo -e "\x1B[34;49m" "Script executed."
echo -e "\x1B[0m"
# Okay, that's the script for yah.
# This script written by krazed of the x86 crew.
# Script rewritten so I could fuck with color codes.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86