checks for layout
This commit is contained in:
parent
5912945ed0
commit
f06b73e8ef
|
@ -73,49 +73,49 @@
|
||||||
# Lesson 3.3.1
|
# Lesson 3.3.1
|
||||||
|
|
||||||
1. The user types the following to their shell:
|
1. The user types the following to their shell:
|
||||||
```
|
```
|
||||||
$ PATH=~/scripts
|
$ PATH=~/scripts
|
||||||
$ ls
|
$ ls
|
||||||
Command 'ls' is available in '/bin/ls'
|
Command 'ls' is available in '/bin/ls'
|
||||||
The command could not be located because '/bin' is not included in the PATH environment variable.
|
The command could not be located because '/bin' is not included in the PATH environment variable.
|
||||||
ls: command not found
|
ls: command not found
|
||||||
```
|
```
|
||||||
* What has the user done?
|
* What has the user done?
|
||||||
* What command will combine the current value of PATH with the new directory ~/scripts?
|
* What command will combine the current value of PATH with the new directory ~/scripts?
|
||||||
1. Consider the following script. Notice that it is using elif to check for a second condition:
|
1. Consider the following script. Notice that it is using elif to check for a second condition:
|
||||||
```
|
```
|
||||||
> /!bin/bash
|
> /!bin/bash
|
||||||
|
|
||||||
> fruit1 = Apples
|
> fruit1 = Apples
|
||||||
> fruit2 = Oranges
|
> fruit2 = Oranges
|
||||||
|
|
||||||
if [ $1 -lt $# ]
|
if [ $1 -lt $# ]
|
||||||
then
|
then
|
||||||
echo "This is like comparing $fruit1 and $fruit2!"
|
echo "This is like comparing $fruit1 and $fruit2!"
|
||||||
> elif [$1 -gt $2 ]
|
> elif [$1 -gt $2 ]
|
||||||
then
|
then
|
||||||
> echo '$fruit1 win!'
|
> echo '$fruit1 win!'
|
||||||
else
|
else
|
||||||
> echo "Fruit2 win!"
|
> echo "Fruit2 win!"
|
||||||
> done
|
> done
|
||||||
```
|
```
|
||||||
* The lines marked with a > contain errors. Fix the errors.
|
* The lines marked with a > contain errors. Fix the errors.
|
||||||
1. What will the output be in the following situations?
|
1. What will the output be in the following situations?
|
||||||
```
|
```
|
||||||
$ ./guided1.sh 3 0
|
$ ./guided1.sh 3 0
|
||||||
$ ./guided1.sh 2 4
|
$ ./guided1.sh 2 4
|
||||||
$ ./guided1.sh 0 1
|
$ ./guided1.sh 0 1
|
||||||
```
|
```
|
||||||
|
|
||||||
## Explorational Exercises
|
## Explorational Exercises
|
||||||
|
|
||||||
1. Write a simple script that will check if exactly two arguments are passed. If so, print the arguments in reverse order. Consider this example (note: your code may look different than this, but should lead to the same output):
|
1. Write a simple script that will check if exactly two arguments are passed. If so, print the arguments in reverse order. Consider this example (note: your code may look different than this, but should lead to the same output):
|
||||||
```
|
```
|
||||||
if [ $1 == $number ]
|
if [ $1 == $number ]
|
||||||
then
|
then
|
||||||
echo "True!"
|
echo "True!"
|
||||||
fi
|
fi
|
||||||
```
|
```
|
||||||
1. This code is correct, but it is not a number comparison. Use an internet search to discover how this code is different from using -eq.
|
1. This code is correct, but it is not a number comparison. Use an internet search to discover how this code is different from using -eq.
|
||||||
1. There is an environment variable that will print the current directory. Use env to discover the name of this variable.
|
1. There is an environment variable that will print the current directory. Use env to discover the name of this variable.
|
||||||
1. Using what you have learned in questions 2 and 3, write a short script that accepts an argument. If an argument is passed, check if that argument matches the name of the current directory. If so, print yes. Otherwise, print no.
|
1. Using what you have learned in questions 2 and 3, write a short script that accepts an argument. If an argument is passed, check if that argument matches the name of the current directory. If so, print yes. Otherwise, print no.
|
||||||
|
@ -125,7 +125,6 @@ fi
|
||||||
## Guided Exercises
|
## Guided Exercises
|
||||||
|
|
||||||
1. Read the contents of script1.sh below:
|
1. Read the contents of script1.sh below:
|
||||||
|
|
||||||
```
|
```
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
@ -145,9 +144,7 @@ fi
|
||||||
echo "here's your cake!"
|
echo "here's your cake!"
|
||||||
exit 0
|
exit 0
|
||||||
```
|
```
|
||||||
|
|
||||||
* What is the output of these commands?
|
* What is the output of these commands?
|
||||||
|
|
||||||
```
|
```
|
||||||
./script1.sh
|
./script1.sh
|
||||||
echo $?
|
echo $?
|
||||||
|
|
Loading…
Reference in New Issue