Instead of running your entire script as root, you could use sudo
in your script to run only the pacman
command as root:
#!/bin/bash
mkdir ~/Documents
sudo pacman -S firefox
This way the Documents/
folder will be created in your user's home directory and then you will be prompted for the root password in order to execute the pacman
command as super user.
Note:
As @jeremysprofile stated in the comments:
You can definitely make folders as root
I suppose the problem is that you expect the Documents/
folder to be created inside your user's home directory. However, if you run you script as root, ~
expands to the super user's home directory: /root/
. So this is where you will your Documents/
folder created with your current script.