There seems to be different home directories depending on whether a script is invoked in the background or not. I have created a simple script with this contents:
#!/bin/bash
ls ~ -al
When running in foreground, it lists the /root directory:
drwx--x--- 7 root root 300 Jul 17 17:31 .
drwxr-xr-x 20 root root 440 Jul 17 17:24 ..
-rw------- 1 root root 16 Jul 17 17:31 .bash_history
-rw-r--r-- 1 root root 316 Jul 15 04:27 .bash_profile
-rwxr-xr-x 1 root root 60 Jul 15 04:27 .bashrc
drwx------ 3 root root 60 Jul 17 17:20 .cache
drwxr-xr-x 4 root root 80 Jul 17 17:20 .config
lrwxrwxrwx 1 root root 30 Jul 15 04:27 .docker -> /boot/config/plugins/dockerMan
drwx------ 3 root root 60 Jul 17 17:20 .local
drwx------ 2 root root 60 Jul 17 17:22 .screen
lrwxrwxrwx 1 root root 21 Jul 15 04:27 .ssh -> /boot/config/ssh/root
-rw-r--r-- 1 root root 180 Jul 17 17:23 .wget-hsts
-rw------- 1 root root 7606 Jul 17 17:20 keyfile
-rw-rw-rw- 1 root root 28512 Jul 17 17:21 patch.sh
When running in background, it lists the / directory:
drwxr-xr-x 20 root root 440 Jul 17 17:24 .
drwxr-xr-x 20 root root 440 Jul 17 17:24 ..
-rw-r--r-- 1 root root 228 Jul 17 17:20 .wget-hsts
drwxr-xr-x 2 root root 3820 Jul 17 17:20 bin
drwx------ 10 root root 4096 Jan 1 1970 boot
drwxr-xr-x 18 root root 3840 Jul 17 17:24 dev
drwxr-xr-x 63 root root 3340 Jul 17 17:24 etc
drwxr-xr-x 2 root root 40 Jul 15 04:27 home
drwxr-xr-x 2 root root 0 Jul 17 17:20 hugetlbfs
lrwxrwxrwx 1 root root 10 Jul 15 04:27 init -> /sbin/init
drwxr-xr-x 1 root root 100 Jun 9 21:34 lib
drwxr-xr-x 7 root root 4440 Jul 17 17:20 lib64
drwxr-xr-x 13 root root 260 Jul 17 17:24 mnt
drwxrwxrwx 4 root root 80 Jul 17 17:24 opt
dr-xr-xr-x 632 root root 0 Jul 17 17:19 proc
drwx--x--- 7 root root 300 Jul 17 17:31 root
drwxr-xr-x 19 root root 1180 Jul 17 17:24 run
drwxr-xr-x 2 root root 5400 Jul 17 17:20 sbin
dr-xr-xr-x 13 root root 0 Jul 17 17:19 sys
drwxrwxrwt 16 root root 440 Jul 17 17:34 tmp
drwxr-xr-x 1 root root 240 Jul 16 12:08 usr
drwxr-xr-x 15 root root 360 Jul 17 17:20 var
Would it be possible to use the /root directory when running in background also?