/var/lib/FILE root:root 0600 (One line of text)
How can I read the /var/lib/FILE into $WID
echo "$PASSWORD" | sudo -S WID=$(cat /var/lib/FILE) not working for me.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
If you need the file's contents in a variable in your current shell, above won't work as the assignment is done in a subshell and be lost after quitting the subshell (admittedly there are shells that do not lose the variable).
sudo to work, you need to have an entry in
sudoers allowing you to run a command. A variable assignment is not a command, thus above will fail again.
If you want a file's contents in a variable without having the permission to read that file, try
WID=$(echo "a" | sudo -S cat /var/lib/FILE)