Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0
On 11/23/2012 07:30 PM, Raphael S Carvalho wrote:
> Hi,
> I found some questions on the internet wondering whether chmod tool does
> support binary numbers as input.
> Even though it doesn't support I downloaded core-utils source and got
> started reading chmode code.
>
> Let's to the point: I added binary input support by making changes
> into the*/lib/modechanges.c
> * file.
> PS: (b) prefix is not case sensitive.
>
> *Tests:*
> ./chmod* b10111* t* *
Thanks for the suggestion. However, I don't think it adds any value, as
bash can already generically process binary numbers at the command line
for ANY application, not just chmod, with just a bit more syntax:
chmod $(printf %o $((2#10111))) t
You can further wrap things in a shell function to reduce your
day-to-day typing:
b2d() {
case $1 in
*[!01]*) echo 'invalid input' 2>&1 ;;
*) eval "printf %d \$((2#$1))" ;;
esac
}
b2o() {
case $1 in
*[!01]*) echo 'invalid input' 2>&1 ;;
*) eval "printf %o \$((2#$1))" ;;
esac
}
chmod $(b2o 10111) t
That is, teaching chmod how to parse binary is just code bloat, when you
already have a generic binary parser in your shell.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc Description: OpenPGP digital signature
[Prev in Thread]
Current Thread
[Next in Thread]
Re: modechange.c (Feature added) - Binary mode support.,
Eric Blake<=