715
edits
Changes
no edit summary
In Python, there is no difference between single quotes. Both allow variable expansion. You can use whichever you prefer.
= ULI101 review === Redirecting and piping output ===== Redirecting output to a file ===In Bash, you can redirect the output of a command to a file with a single > between the command and the file. Note, this will overwrite the file. You can also append the output to a file with two >> between the command and the file. This will add the content to the file, not overwrite the file. In both cases if the file does not exist it will be created.
== Basic commands ==
* cat: Cat is used to display the content of a file or files. If given multiple filenames it will combine (concatenate) them in the output.* grep: Grep is used to search for patterns using regular expressions.* cut: Cut is handy for isolating information from command output and storing it in a variable.
== Conditional statements ==
==='''Bash'''===* Conditional statements or ifstatements are used in scripts to add logic. You can test to see if a condition is met and change the behaviour of the script as a result of that condition. Here is a sample if statement:<pre>if [[ $grade -ge 50 ]]; then echo "Congratulations, you passed!"else* test echo "I'm sorry, [you failed."fi</pre>
'''Python'''
*Python has conditional statements, we just haven't covered them yet. We will cover them in a future lecture.
= Exercises =
You can do these exercises in any order, and change them in any way you like.
* Create a bash script that will print Hello, then list the contents of the / directory, then print Good Bye.
**Create a python script that does the same thing.