Using whoami is good choice. The $() construct in bash tells the shell to execute the command it finds inside the parentheses and return the result as a string.
Usually systems create "environmental variables" like $USER and $HOME when someone logs in.
Code:
seiji@Linux:~$ echo $USER
seiji
seiji@Linux:~$ echo $HOME
/home/seiji
Now if you're trying to write a script that would run correctly across all platforms and shells, that's way beyond my abilities. In fact, I'm not sure it's possible. Even on Linux, you can have different shells with different commands and environments. In scripts, it's always a good idea to specify bash explicitly like:
Code:
#!/bin/bash
echo $USER
echo $HOME
You can see the entire array of default environment variables with the "printenv" command.