Actually we can go through the script line by line:
This line tells which interpreter to use. Bash in this case.
Code: Select all
BROWSER="iceape"
FILEMAN="pcmanfm"
ICONS="moblin-icon-theme"
MAIL="sylpheed"
PLAYER="audacious"
TERM="lxterminal"
MANAGER="lxappearance"
These are the variables that don't need to be capitalized, but it's important that we put the equal and quote signs there.
Code: Select all
function docmd() {
# set of commands
}
That's a function, we only check the first and the last line. The function is called docmd and always remember to put the curly brackets there. Inside of this function there's a set of instructions and commands that are called. It's important to indent them when certain interpreters are used.
Code: Select all
# first Pidsley has set a variable. cmd, this time not capitalized, equals $@ - it shows the actual command that is going to be executed
cmd=$@
# as next the echo command displays the $cmd variable (that is $@) on the screen
echo $cmd
# the 'read' command is waiting for user input
read -n1 -p 'run command? (y/n/a) '
# a simple echo will display a blank line
echo
# the variable ans equals the previously entered letter by the user
ans=$REPLY
# if this letter is exactly equal 'a' then
if [ $ans == 'a' ]; then
# the script will print 'abort' on the screen and
echo 'abort'
# exit with exit code 1
exit 1
# else, if the answer is 'y' then
elif [ $ans == 'y' ]; then
# it first prints a message (that it's running the previously set command)
echo -e '\nrunning '$cmd'\n'
# and finally calls the command
$cmd
# and because it is an if-loop, we close the loop with 'fi'
fi
I've added comments here.
Code: Select all
docmd "sudo apt-get update"
docmd "sudo apt-get install --no-install-recommends" $BROWSER $FILEMAN $ICONS $MAIL $PLAYER $TERM $MANAGER
Here the actual work is being done. Every docmd line runs the set of commands that were put into the function before. As rhosenbush pointed out, it's not only for lazy people, but also good to keep the code clean and unbloated :D