binary = function(n) // number b = [] while n > 0 division = n % 2 b.push(division) n = floor(n / 2) end while while b.len < 3 b.push(0) end while b.reverse return b end function to_perm = function(n, m) // number 0 or 1, mode if n == 1 then return "+" + m else return "-" + m end if end function perm_query = function(n, c) // number, class b = binary(n) pq = [] pq.push(c + to_perm(b[0], "r")) pq.push(c + to_perm(b[1], "w")) pq.push(c + to_perm(b[2], "x")) return pq end function if params.len < 2 or (params.len == 3 and params[0] != "-R") then exit("learn how to use chmod yourself :)") perms = params[0] pathFile = params[1] isRecursive = 0 if params.len == 3 then perms = params[1] pathFile = params[2] isRecursive = 1 end if u = perms[0].to_int g = perms[1].to_int o = perms[2].to_int queries = [] queries = queries + perm_query(u, "u") queries = queries + perm_query(g, "g") queries = queries + perm_query(o, "o") file = get_shell.host_computer.File(pathFile) if file == null then exit("chgmod: can't find " + pathFile) for query in queries output = file.chmod(query, isRecursive) if output then print(output) end for