Folks,

This is a Linux-oriented question.

I am writing a script that may be executed by a user with admin privileges, if required, on a root-userless K/Ubuntu system. I want to make sub-directories under a parent using sudo with the same UID as the parent directory. I am also trying to copy files from one directory to another in this case using the UID of the target directory.

In the scripts, the relevant lines are:

-------
system "sudo -u \#$uid mkdir -m 755 $rootdir"; # (A)

and

system "sudo -u \\#$uid cp $fontdir/*.$fontdoc $paths{doc}"; # (B)
-------

where

$uid is a UID obtained using File::stat or supplied as an argumnent;
$rootdir is a fully qualified path to a directory being crated;
$fontdir/*.$fontdoc is a set of globbed source files being copied;
$paths{doc} is that target directory to which these files are being copied.

The values of these variables are not relevant to this question.

I have found that in bash or dash as the shell in Linux, I need to backslash the hash character # to give a numeric UID to sudo because the shell (like Perl) interprets # as a comment character.

Strangely, I have found by trial and error that a single backslash-hash (\#) is needed for statement (A) to work but a double backslash-hash (\\#) is needed for statement (B) to work. Changing both to single or double backslashes results in error messages from the shell.

Can someone please explain why this is so and what is going on?

Kindly copy replies to my email address as I am not always able to access this newsgroup.

Thanks.

Chandra
17 Nov 07
P.S. I have not used existing modules for creating directories or copying files because they do not allow UID-specific directory and file ownership.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to