Open main menu

CDOT Wiki β

Changes

Tutorial12: Shell Scripting - Part 2

689 bytes removed, 06:40, 18 March 2021
KEY CONCEPTS
= KEY CONCEPTS =
===Additional Logic Control Flow Statements===
<br>
<span style="font-family:courier;font-weight:bold;">num1=5<br>num2=10<br>if test $num1 –lt $num2<br>then<br> &nbsp;&nbsp;&nbsp;echo “Less Than”<br>elif test $num1 –gt $num2<br>then<br> &nbsp;&nbsp;&nbsp;echo “Greater Than”<br>else &nbsp;&nbsp;&nbsp;echo “Equal to”<br>fi</span><br><br>
===Additional Loop Statements===
'''Command Substitution:''' [[Image:for-command-substitution.png|thumb|right|300px|Example of how a '''for loop with command substitution''' works.]]<i>'''Command substitution''' is a facility that allows a command<br>to be run and its output to be pasted back on the command line as arguments to another command.</i><br>Reference: https://en.wikipedia.org/wiki/Command_substitution<br><br> ''Usage:'' <span style="font-family:courier"><b>command1 $(command2)</b><br>or<br><b>command1 `command2`</b></span><br><br> ''Examples:'' <span style="font-family:courier;font-weight:bold">file $(ls)<br>mail -s "message" $(cat email-list.txt) < message.txt<br><br> '''==Using the for Loop with Command Substitution'''====
Let’s issue the for loop with a list using command substitution.<br>In the example below, we will use command substitution to issue the ls command and<br>have that output (filenames) become arguments for the for loop.<br><br>
13,420
edits