Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| linux:bash [2023/03/07 11:01] – [Linux.Bash] admin | linux:bash [2024/02/14 06:45] (current) – [Linux.Bash] admin | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| </ | </ | ||
| + | <code BASH> | ||
| + | # check xterm color | ||
| + | msgcat | ||
| + | </ | ||
| + | ++++ Пример| | ||
| + | {{: | ||
| + | ++++ | ||
| + | <code BASH> | ||
| # grep for configuration without comment line | # grep for configuration without comment line | ||
| egrep -v " | egrep -v " | ||
| + | </ | ||
| bash | bash | ||
| * [[https:// | * [[https:// | ||
| Line 141: | Line 149: | ||
| ===== Scripting ===== | ===== Scripting ===== | ||
| * scripting pitfails https:// | * scripting pitfails https:// | ||
| + | |||
| + | |||
| + | ===== Scripting-code ===== | ||
| + | * read line by line - https:// | ||
| + | |||
| + | <code BASH> | ||
| + | |||
| + | #!/bin/bash | ||
| + | |||
| + | # Declare variables | ||
| + | vm_name="" | ||
| + | vm_path="" | ||
| + | skipped_lines="" | ||
| + | current_line_number=1 | ||
| + | |||
| + | # Read the file line by line | ||
| + | while IFS=';' | ||
| + | # Check if the line has the correct format | ||
| + | if [[ -z " | ||
| + | skipped_lines=" | ||
| + | fi | ||
| + | |||
| + | # Process the variables here if the line has the correct format | ||
| + | if [[ -n " | ||
| + | echo "VM name: $vm_name" | ||
| + | echo "VM path: $vm_path" | ||
| + | fi | ||
| + | |||
| + | # Increment the line number | ||
| + | current_line_number=$((current_line_number+1)) | ||
| + | done < file.txt | ||
| + | |||
| + | # Print the skipped lines | ||
| + | if [[ -n " | ||
| + | echo "The following lines were skipped because they did not have the correct format:" | ||
| + | echo " | ||
| + | fi | ||
| + | </ | ||