checks for layout

This commit is contained in:
waldek 2021-04-10 14:07:05 +02:00
parent 1bf0caa082
commit 5912945ed0
1 changed files with 33 additions and 30 deletions

View File

@ -125,42 +125,45 @@ fi
## Guided Exercises ## Guided Exercises
1. Read the contents of script1.sh below: 1. Read the contents of script1.sh below:
```
#!/bin/bash
if [ $# -lt 1 ] ```
then #!/bin/bash
echo "This script requires at least 1 argument."
exit 1
fi
echo $1 | grep "^[A-Z]*$" > /dev/null if [ $# -lt 1 ]
if [ $? -ne 0 ] then
then echo "This script requires at least 1 argument."
echo "no cake for you!" exit 1
exit 2 fi
fi
echo $1 | grep "^[A-Z]*$" > /dev/null
if [ $? -ne 0 ]
then
echo "no cake for you!"
exit 2
fi
echo "here's your cake!"
exit 0
```
echo "here's your cake!"
exit 0
```
* What is the output of these commands? * What is the output of these commands?
```
./script1.sh
echo $?
./script1.sh cake
echo $?
./script1.sh CAKE
echo $?
``` ```
./script1.sh
echo $?
./script1.sh cake
echo $?
./script1.sh CAKE
echo $?
```
2. Read the contents of file script2.sh: 2. Read the contents of file script2.sh:
``` ```
for filename in $1/*.txt for filename in $1/*.txt
do do
cp $filename $filename.bak cp $filename $filename.bak
done done
``` ```
* Describe the purpose of this script as you understand it. * Describe the purpose of this script as you understand it.
## Explorational Exercises ## Explorational Exercises