I created a simple script like the following called "/usr/bin/mytool1" and make it executable.
#!/usr/bin/rlwrap /usr/bin/perl
while (1) {
chomp($cmd = <STDIN>);
print "cmd=$cmd\n";
}
The problem is, if I run it as a regular user, it works fine.
Then I did a "sudo bash" and as root, I run mytool1, it works fine too.
Now I am back as a regular user, running command "mytool1" will give error like:
rlwrap: cannot read and write /home/user1/.perl_history: Permission denied
I did some investigation, here is what I found:
$ ls -l /home/user1/.perl_history
-rw------- 1 root root 138 Dec 6 18:13 /home/user1/.perl_history
The problem here is, rlwrap will change the owner of /home/user1/.perl_history to root when it runs as root.
I think this is a bug on rlwrap because in the case Ubuntu, $HOME didn't change after I run sudo bash, rlwrap should have used $USER to construct the history file.
What do you think?
There is no need to modify and recompile
rlwrap, just specify the history file on the command line:I am surprised that Ubuntu's
sudopreserves$HOMEby default, I cannot see why this would ever be useful (there are occasional murmurings against this policy on the Ubuntu lists, but certainly no storms of protest)In the meantime, I will keep
rlwraps behaviour as it is, but try to find out whether and how other programs avoid problems like this (not all of them do)Edit (aug 2019): From
sudo - 1.8.27-1ubuntu2onwards Ubuntu (finally!) restoressudohandling of$HOMEto what everyone else does : it will not preserve$HOMEby default. This means thatrlwrapwill be able to read and write its own history when running undersudo, even without the extra--history-filenameargument.Hans (
rlwrapmaintainer)