mgualtieri


Joined 1 year ago
Homeworks submitted:
Homework comments:
2
1

About Me

No description provided.

Classes

Bash Scripting

Class status: Established
Role: Student
. 11% complete

Submitted Assignments

Bash Scripting: Lesson 2, HW 1

Yikes. I see what everyone's saying about 3.6; that really is out of place. I see what they're trying to do, but the examples were so poor that the lesson is almost lost.

For one, I'm not sure that they mentioned anywhere how the scripts even call the functions -- there's supposed to be something like what I've got below so you can source the functions files, otherwise the script has no idea what you're talking about. I'll show what I mean below.

One other nitpick: the book makes a little typo -

printf "%b" "Overriding $THISPACKAGEwith ${CHOICE}n"

specifically $THISPACKAGEwith .. I'll mark it down in the code below.

Maybe I had this all wrong, but that's how I saw it.

Now, the "select" stuff, that was pretty awesome!

#!/bin/bash

#source the function we want to use

source ~/func_choice.1

#also, the syntax '. ~/func_choice.1' (no quote marks, duh) works for that as well

THISPACKAGE=`date`  # this wasn't included in the bash cookbook...?

until [ "$CHOICE" = "y" ]; do
        printf "%b" "This package's date is $THISPACKAGE\n" >&2
        choice "Is that correct? [Y/,<New date>]: "
        if [ -z "$CHOICE" ]; then
                CHOICE='y'
        elif [ "$CHOICE" != "y" ]; then
             
# typo on the line below, should be "$THISPACKAGE with"
# below the dashes are the examples WITH the correct spacing, 
# and without the spacing is the example right below it 

            printf "%b" "Overriding $THISPACKAGEwith ${CHOICE}\n" 
                THISPACKAGE=$CHOICE
        fi
done

[root@atlas ~]# 

-------------------

[root@atlas ~]# ./choice.sh 

This package's date is Fri Nov 26 21:39:39 PST 2010
Is that correct? [Y/,<New date>]: 11/27/2010
Overriding  11/27/2010
This package's date is 11/27/2010
Is that correct? [Y/,<New date>]: y

[root@atlas ~]# 

[root@atlas ~]# ./choice.sh 

This package's date is Fri Nov 26 21:39:08 PST 2010
Is that correct? [Y/,<New date>]: 11/27/2010
Overriding Fri Nov 26 21:39:08 PST 2010 with 11/27/2010
This package's date is 11/27/2010
Is that correct? [Y/,<New date>]: y


 


mgualtieri 1 year ago
Bash Scripting: Lesson 1, HW 1

I'm late to the party!

I've been doing shell scripting for a while now, but I learned a lot of stuff from this chapter -

for instance, the fact that { } and also ( ) will group commands together so you can redirect to a single file - the braces have a few more quirks though, with the whitespace requirement and the trailing semicolon. That will come in useful in some scripts I'm writing.

Also, I was always confused by the $( ) as a substitute for backticks. I prefer the look of $( ) to the backticks, but I understand that the backticks provide more backwards compatibility.

'tee' is awesome for logging... I use tee -a to append to logfiles when I want both stdout and stderr redirect, while still showing output on the screen. Helpful when you're sitting in front of a terminal running a script but you still want logging so you don't have to put a thousand 'sleep' commands in there so you can catch up ;-)


mgualtieri 1 year ago