My current snippet of code looks like this ...
#Location of network config files nfds="/etc/sysconfig/network-scripts/" #Standard prefer of network config files fil="ifcfg-" #Array variable that feeds "$nic" cards= array loop built from "nic=$(ls /sys/class/net | grep en)" #Set color for Divice labile div="\033[38;5;39m" #Set Fix format and colour info fix="\033[38;5;118m" #Set color for OK ok="\033[38;5;28m" #Clear All font and color info ctf="\033[0m" function currentCardDefRoute(){ defr=$(grep DEFROUTE $nfds$fil$cards | cut -d = -f 2) if [[ $defr = "yes" ]] || [[ $defr = "no" ]]; then echo -e " "$div$cards$ctf"'s current default route is\t"$div$defr$ctf"\t\t\t\t ["$ok"OK"$ctf"]" $st else echo -e " "$div$cards$ctf"'s current default route is \t"$fix"Missing"$ctf"\t\t\t ["$fix"PLEASE FIX"$ctf"]" $st fi } I indent 1 space on all echo lines for readability and consistent formatting. Keeping output readable and easy to understand.
Im looking to us the "columns" option and make the output more dynamic and have the format consistent no matter the screen size or var result. I would love to also get rid of all the "\t"s in my code. I have tried printf to no success.
I googled a lot of different ways and not seen the specific answer Im looking for or a variation I can draw an answer from.
Thank you for your help. btw. This is the first code I have ever written so go easy guys :)
printfshould be where you're spending your time on research. Once you understand 20-30% of theman printfdoucmentation (by doing small samples), the rest will be obvious. Someprintfman pages even have a section labeledexamples. Good luck.ctag, I'll mention that theprintfin theclanguage is the "parent" of the shellprintffunctions. I'm not sure if you think you need to code incto useprintf, but you don't. (This one looks pretty good, but the features may differ depending on shell and OS versions : ss64.com/bash/printf.html ) . Good luck.printfas defined by the tag (which is related to the C functions C).$varinside double-quoted strings. You don't have to open and close the strings around them.