0

I have a small CLI script that checks for the existence of a file in a user's home directory:

$ do_my_script
#!/bin/bash
if test -e ~/.myfiledirectory/.myfile; then ... do something

It works great when I run it as my logged in user. Though, this script needs to be run as sudo sometimes...

sudo do_my_script
#!/bin/bash
if test -e ~/.myfiledirecotry/.myfile; then ... do something

If I run it as sudo... I belive it is checking the super user's home directory for the existence of the file, instead of the logged in user's home directory.

I am trying to get it to always check the currently logged in user's home directory for the existence of the file, regardless if the command is run as sudo or not.

Any help is appreciated! Thanks!

Nick McLean
  • 601
  • 1
  • 9
  • 23

0 Answers0