fdisk -l output with partition label appended - Bash script available
This ugly bash script does it. Feel free to improve. Could become a function or alias.
I could never remember which partition was what. Code:
#!/bin/bash |
fdisk -l > monfdisk.txt
Ah, you mean like "ln -sf /etc/shadow ./monfdisk.txt"? Better use mktemp.And you don't really need a tempfile and [ $nb_char -gt 4 ] seems a bit too generic a test to me, maybe make it "expr match string regex" or just test: fdisk -l|while read l; do l=(${l}); [ "${l[0]:0:5}" = "/dev/" ] `e2label $resu 2>/dev/null` I am allergic to backticks as it makes for bad readability, but that's my personal gripe I guess. What you *could* do is make errors work for you by using var=$(e2label $resu 2>/dev/null) and echo "${var:=No label found}" This ugly bash script does it. Hmm. For me it doesn't (fdisk v2.11y), but why not just: Code:
fdisk -l|grep /dev/[s,h]d..*83..*Linux$|awk '{print $1}'|\ |
thanks a lot for the suggestions (Still learning)
# fdisk -v fdisk v2.12a I wonder what changed between version (formating?) Quote:
Quote:
but why not just: Code:
disk -l|grep /dev/[s,h]d..*83..*Linux$|awk '{print $1}'|\ 2) I want the rest of fdisk -l intact 3) I see your point, one can get inspired from your example >>Or am I missing something vital here? Yes, I am just a hobbyist ;) I want the rest of fdisk -l intact With the above code, result is Quote:
|
I wonder what changed between version
Prolly nothing much I can see. Anyway. Here's some "sh -x myfdisk.sh" output of two partitions: Code:
+ read line Yes, an ugly temp file this is. Will try a way round it. Well, if you want to avoid using mktemp, then maybe tempf=$(date|sha1sum); tempf=${tempf:0:30}; tempf="${TMPDIR:=$HOME}/myfdisk.$tempf" With the above code, result is Maybe the regex should read "/dev/[s,h]d.*[[:blank:]]83[[:blank:]].*Linux$", but I'm pretty sure the type 83 should exclude "empty" containers. Hmm. BTW, got yourself a copy of the ABS or "Advanced Bash Scripting" guide? Has some helpful stuff. |
Code:
+ '[' 10 -gt 4 ']' The guilty code line is echo "$line"" ------------>"`e2label $resu 2>/dev/null` Quote:
that e2label is not in the path? Ta, I have the advanced bash available. This is only my third bash script, so I really struggle with remembering syntax or being inventive. I will try to improve with your latest suggestion, and with a ^/dev/ regexp and a sed -i that should work (it is piping with sed that always trouble me, I tried early on but failed) |
So is this a bash version issue, a backtick issue, or just that e2label is not in the path?
No, none of that. My fault was I, ahhh "customised", tempfile usage w/o noticing later on. Works as advertised. |
Improved script - no temp file. Reiserfs included. Better coding
Et voila. Less ugly. It does the job I wanted.
Can be improved as needed. Cannot make it a one liner, sorry... Output example Code:
/dev/hdb3 10641 11659 8185117+ 83 Linux --------> suse Code:
#!/bin/bash |
Dunno if it qualifies, you determine yourself, but maybe it's something to add a pointer to in the Tips 'n tricks thread.
|
All times are GMT -5. The time now is 04:38 PM. |