Welcome to Cloud Academy's lab guide for Practicing Shell Scripting Fundamentals.
Learning how to write scripts is essential to any administrator or cloud professional. Automating repetive or multi-step tasks can make the difference between a success organization or not. In this lab, we walk you through scripting fundamentals for AWS Linux.
The most common topic students report is logging into the server and editing the code. Below, you can find some extra steps to both issues:
Logging in
-
Ensure that the lab environment has loaded 100% prior to clicking it.
-
Once the environment is fully loaded, click on Open development env, which should open a new tab. Please log in using provided details from this step:https://app.qa.com/lab/practicing-shell-scripting-fundamentals/accessing-the-amazon-linux-2-terminal/. Username is ca and there is no password, so just click enter on your keyboard
-
Also, from this step, enter the command "tree" in the prompt to display the directories:
-
Once finished, please click "Next"
Modifying the Code
On this step: Modifying Your Lab Shell Script, the lab reviews different ways to modify files in the shell. You can use any editor you like such as VIM, NANO, or Emacs. To open the file in either of those editors, please see the below examples:
-
-
Vim: vim SCRIPT_NAME
-
Nano: nano SCRIPT_NAME
-
Emacs: emacs SCRIPT_NAME
-
-
in case you are not yet familiar with these commands, please refer to the below lectures:
-
You may then click next once you are done reading up on this step.
On this step: Declaring and Using Shell Variables, you are given the below mission: "lab_script.sh, declare a variable FILE, and set the value to the string sample.txt. Reference the variable within a string to echo File to test: sample.txt to the screen when the lab_script.sh is run."
To do this, enter the below command onto the shell.
Remember that you would need to edit lab_script.sh, as in the previous step, you would use either VIM, Nano, or emacs. I have used nano for this lab.
nano lab_script.sh
The file will open in the terminal.
The first code you would need to add is:
FILE="sample.txt"
echo "File to test: ${FILE}"
It should look like this in the shell:
To save, click CTRL+S.
This should let you pass the check:
Click next.
5. In this step, Incorporating Tests with Conditional Statements, another mission is stated. To pass, use the below code:
if [ -s $FILE ]
then
echo "File exists and contains text."
elif [ -e $FILE ]
then
echo "File exists but is empty."
else
echo "File does not exist."
fi
This should let you pass the check:
Make sure to paste it in the correct location, it should look like the screenshot below:
To save, click CTRL+S once again.
This should let you pass the check, and you may then click next for the last step.
6. In the last step:Looping Through Command Line Arguments, use the below code:
for VALUE in $@
do
echo "Parameter: ${VALUE}"
done
Make sure this is pasted on the correct location as well, it should look like this::
Click CTRL+S once again to save.
This should let you pass the last check...
and finish the lab...
I hope this lab guide helps, and in case you encounter any errors or need further assistance, please email support@cloudacademy.com.
Happy Training!
Comments
0 comments
Article is closed for comments.