Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

454 bytes added, 09:39, 5 March 2021
Using Variables in Shell Scripts
Refer to the diagram to the right for examples using positional and special parameters.
 
 
=== Command Substitution / Math Operations ===
<span style="font-family:courier;font-weight:bold">file $(ls)<br>mail -s "message" $(cat email-list.txt) < message.txt<br>echo "The current directory is $(pwd)"<br>echo "The current hostname is $(hostname)"<br>echo "The date is: $(date +'%A %B %d, %Y')"<br>
 
 
Math Operations:
 
 
=== Math Operations: ===
 
In order to make math operations work, we need to convert numbers stored as text into binary numbers. We can do this by using the expr command or simply by using 2 pairs of round brackets (( )).
Examples:
 
<pre style="width:20%">num1=5;num2=10
echo “$(($num1 + $num2))”
15
echo “$((num1-num2))”
-5
((product=num1*num2))
echo “$product”
50
</pre>
===Using Control Flow Statements in Shell Scripts===
13,420
edits

Navigation menu