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 = );
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?


Check Solution