Log in to pe15
- Run the ssh client
Use the values in the table below to connect to pe15.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host pe15.cs.umb.edu user name your Unix username Authentication method password
- Enter your password
A dialog box will appear on the screen into which you must type the password for your Unix account.
Directory for This Exercise
(When you are ready for me to check this exercise, please scroll back up to where you entered these commands!)
- Go to your ex directory
cd ~/it244/ex- Create an ex19 directory
mkdir ex19- Go to your ex19 directory
cd ex19Start Up a script Session
Execute the script command, using the --flush option
script --flushRunning Processes
- Look at the processes currently running
ps -fThe -f option to ps gives you more information about running processes.
UID The username of the account that started the process PID The process ID PPID The process ID of the parent process STIME When the process started CMD The command line that started the process
- Run a job along with ps
sleep 120 & ps -fNotice that the process ID of the parent process that called sleep and ps -f is the process ID of your shell.The Process Hierarchy
- Run pstree while several sleep processes are running
sleep 20 & sleep 20 & pstree -phLook at the bold line of processes, which denotes your shell. You will notice sleep processes running under your bash shell.Positional Parameters
- Copy print_positionals.sh to your current directory
cp ~ckelly/course_files/it244_files/print_positionals.sh .- Look at the contents of this script
cat print_positionals.shThe script simply prints the first four tokens on the command line.
- Run print_positionals.sh with three arguments
./print_positionals.sh foo bar bletchNotice that the first positional parameter printed, 0, is the name of the command.
- Copy print_arg_numbers.sh to your current directory
cp ~ckelly/course_files/it244_files/print_arg_numbers.sh .- Look at the contents of this script
cat print_arg_numbers.sh- Run this script with some arguments
./print_arg_numbers.sh foo bar bletchThe script prints the number of arguments given to it on the command line.Quotes with Variables
- Set a local variable
city=Boston- Display the value of this variable
echo $city- Set a new variable to the value of this variable without quotes
new_city=$city- Display the value of this new variable
echo $new_cityThe value of the new variable has been set to that of the old variable.
- Repeat the above using single quotes
new_city='$city'- Display the new value of the variable
echo $new_cityNotice the dollar sign, $ , indicating that the variable was not evaluated.
- Repeat the above using a backslash before the dollar sign
new_city=\$city- Display the new value of the variable
echo $new_cityAgain the dollar sign appears.
- Set a variable using double quotes, " "
new_city="$city $city $city"- Display the new value of the variable
echo $new_cityThe values of each of the variables was substituted properly in the new value, along with the spaces between them.
- Set a variable using a phrase
cheer="Go Red Sox"- Display the value of this new variable
echo $cheerRemoving a Variable's Value
- Set two variables
city=Cambridge ; state=MA- Display the values of these new variables
echo $city ; echo $state- Unset city using unset
unset city- Display the value of city
echo $citycity now has no value.
- Remove the value of state by assigning it the empty string
state=- Display the value of state
echo $stateNow state has no value.
Making a Variable Read Only
- Create the variable team
team=Patriots- Display the value of team
echo $team- Change the value of team
team="Red Sox"- Display the value of team
echo $team- Make team read only
declare -r team- Try to change the value of team
team=CelticsYou can't change the value because team is now read only.Exit Your script Session
Use the exit command
exitYou should see a confirmation message confirming that the script session is finished, resulting in a file called typescript. I will look at the typescript file, along with the other files in your directory.Bash Script for This Exercise
- Go to your ex19 directory
cd ~/it244/ex/ex19- Create the script ex19.sh
nano ex19.sh- Write into this file commands from certain of the sections above
Include Unix commands from the section Positional Parameters, to the section Making a Variable Read Only.
- Save this file
Save and quit.
- Make this scipt executable
chmod 755 ex19.sh- Test the script
./ex19.shFix any errors you find.
If you have trouble, see me.