Log in to users
- Log in to a Windows machine or your own laptop
Enter your Unix username as the account name. Then enter your password.
- Run the ssh client
Use the values in the table below to connect to users.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host users.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
- Go to your ex directory
cd ~/it244/ex- Create an ex26 directory
mkdir ex26- Go to your ex26 directory
cd ex26Here Document
- Using nano, or an editor of your choice, create here.sh
#! /bin/bash # # demonstrates how here documents work echo -n "Here is the information you requested: " grep $1 <<EOF Boston Red Sox New York Yankees Toronto Blue Jays Baltimore Orioles Tampa Bay Rays EOF- Make this script executable
chmod 755 here.sh- Run this script a couple of times
./here.sh Boston ./here.sh Rays ./here.sh OrioBraces with Variables
- Define the variable foo
foo=FOO- Display the value of foo
echo $foo- Use foo with a period
echo $foo.bar- Use foo with a slash
echo $foo/bar- Use foo concatenated with another string
echo $foobarbash does not see the variable foo followed by the string "bar".
It sees a new variable, foobar.
- Use foo concatenated with another string, but using braces
echo ${foo}barSpecial Parameters
- Look at the running processes
ps- Use the $$ special parameter
echo $$The value returned by $$ is the process ID of your current shell.
- Run a command that succeeds
ls- Use the $? special parameter
echo $?The command returns 0 since the previous command executed successfully.
- Run a command that fails
ls xxxxx- Use the $? special parameter
echo $?The command returns 2 indicating that the previous command failed.
- Run a command in the background
sleep 120 &- Use the $! special parameter
echo $!The number returned is the same as the PID that appeared on the command line when the background job was created.Positional Parameters
- Using nano or an editor of your choice, create the script positionals.sh
#! /bin/bash # # prints the values of the various positional parameters echo "This shell script was called using $0" echo "This shell script was called using $# command line arguments" echo "Here are the command line arguments: $@" echo "Positional parameter 1: $1" echo "Positional parameter 2: $2" echo "Positional parameter 3: $3"- Make this script executable
chmod 755 positionals.sh- Run positionals.sh with some arguments
./positionals.sh foo bar bletchshift
- Using nano, or an editor of your choice, create the following shell script shift.sh
#! /bin/bash # # uses shift to print the positional arguments while [ $# -gt 0 ] do echo $1 shift done- Make this script executable
chmod 755 shift.sh- Run this script with a couple of arguments
./shift.sh foo bar bletchThe shift command moves each command line argument in turn into the first positional parameter, allowing us to print each argument until there are no more command line arguments left.set
- Using nano, or an editor of your choice, create the following shell script set.sh
#! /bin/bash # # uses set to create arguments echo "Here are the arguments given to this script: $*" set foo bar bletch echo "After calling set" index=1 while [ $# -gt 0 ] do echo "Positional parameter $index: $1" shift (( index += 1 )) done- Make this script executable
chmod 755 set.sh- Run this script with no arguments
./set.shEven though no arguments were given to the script at the command line, set created these arguments from within the script.