Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| bash_scripting [2017/04/25 17:43] – mgupton | bash_scripting [2017/07/11 19:21] (current) – mgupton | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ======Bash Scripting====== | ======Bash Scripting====== | ||
| ======Conditionals====== | ======Conditionals====== | ||
| - | * The special variable ''?'' | + | * The special variable '' |
| <code bash> | <code bash> | ||
| Line 73: | Line 73: | ||
| ======File Manipulation====== | ======File Manipulation====== | ||
| ==Delete a file if it exists.== | ==Delete a file if it exists.== | ||
| - | < | + | < |
| [[ -f " | [[ -f " | ||
| </ | </ | ||
| + | |||
| + | ======File I/O====== | ||
| + | |||
| + | ===Read a text file line by line.=== | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | while read line | ||
| + | do | ||
| + | name=$line | ||
| + | echo "Text read from file - $name" | ||
| + | done < $1 | ||
| + | </ | ||
| + | |||
| + | ===Read each line of a file as a CSV record.=== | ||
| + | <code bash> | ||
| + | while IFS=, read col1 col2 | ||
| + | do | ||
| + | echo "I got: | ||
| + | done < myfile.csv | ||
| + | </ | ||
| + | |||
| + | ======Resources====== | ||
| + | * [[http:// | ||