13,420
edits
Changes
no edit summary
|- valign="top"
|
{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''Data Input:'''<br><br>A shell script can obtain data from a number of methods: '''reading input files''', using '''arguments when issuing command''' (positional parameters), or '''prompting for data to store in a variable'''. The later method can be accomplished by using the '''read''' command, for example: '''read -p "Enter your name: " userName'''.<br><br></li><li>'''Mathematical Expressions:'''<br><br>In shell scripting, data is stored in variable as text, not other data types (ints, floats, chars, etc) like in compiled programs like C or Java. In order to have a shell script perform mathematical operations, number or variable need to be surrounded by two sets of parenthesis ((..)) in order to convert a number stored as text to a binary number.<br><br><u>'''Examples'''</u><br><br></li><li>'''Loops (iteration):'''<br><br>x<br><br>'''<u>Examples (try in a shell script)</u>'''<br><br>''set ops235 is fun''<br>''for x''<br>''do''<br> ''echo "argument is $x"''<br>''done''<br><br>''for x in $(ls)''<br>''do''<br> ''echo "Filename: $x"''<br>''done''<br><br>''read -p "enter a whole number: " num''<br>''until echo $num | grep -q "^[0-9][0-9]*$"''<br>''do''<br> ''read -p "Incorrect. Please enter WHOLE NUMBER: " num''<br>''done''<br><br></li></ul>}}
|}