mercredi 25 février 2015

Can the following test conditon be simplified

I have a variable a, if I echo it it gives me.



lrwxrwxrwx 1 root root 23 May 16 2014 ggo -> /export/s1/home/ggo


The following code checks if the owner or group is a number or root. If either the owner or group is a number or root, then it will print the name of directory, in this case ggo.



if [[ $(echo $a|awk "{print \$3}") =~ ^[0-9]+$ ]] || [[ $(echo $a|awk "{print \$3}") == root ]] || [[ $(echo $a|awk "{print \$4}") =~ ^[0-9]+$ ]] || [[ $(echo $a|awk "{print \$4}") == root ]] ; then echo $(echo $a | awk "{print \$9}"); fi;


However can it be simplified?


For example cant the following section be condensed:



[[ $(echo $a|awk "{print \$3}") =~ ^[0-9]+$ ]] || [[ $(echo $a|awk "{print \$3}") == root ]]

Aucun commentaire:

Enregistrer un commentaire